mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-20 15:10:59 +08:00
fix(InputBar): move focus logic into useEffect to prevent side effects
fix: Error: Cannot access refs during render
This commit is contained in:
parent
24d2e6e6ce
commit
254051cf62
@ -3,7 +3,7 @@ import { useTimer } from '@renderer/hooks/useTimer'
|
|||||||
import { Assistant } from '@renderer/types'
|
import { Assistant } from '@renderer/types'
|
||||||
import { Input as AntdInput } from 'antd'
|
import { Input as AntdInput } from 'antd'
|
||||||
import { InputRef } from 'rc-input/lib/interface'
|
import { InputRef } from 'rc-input/lib/interface'
|
||||||
import React, { useRef } from 'react'
|
import React, { useEffect, useRef } from 'react'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
|
|
||||||
interface InputBarProps {
|
interface InputBarProps {
|
||||||
@ -27,9 +27,13 @@ const InputBar = ({
|
|||||||
}: InputBarProps & { ref?: React.RefObject<HTMLDivElement | null> }) => {
|
}: InputBarProps & { ref?: React.RefObject<HTMLDivElement | null> }) => {
|
||||||
const inputRef = useRef<InputRef>(null)
|
const inputRef = useRef<InputRef>(null)
|
||||||
const { setTimeoutTimer } = useTimer()
|
const { setTimeoutTimer } = useTimer()
|
||||||
if (!loading) {
|
|
||||||
setTimeoutTimer('focus', () => inputRef.current?.input?.focus(), 0)
|
useEffect(() => {
|
||||||
}
|
if (!loading) {
|
||||||
|
setTimeoutTimer('focus', () => inputRef.current?.input?.focus(), 0)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<InputWrapper ref={ref}>
|
<InputWrapper ref={ref}>
|
||||||
{assistant.model && <ModelAvatar model={assistant.model} size={30} />}
|
{assistant.model && <ModelAvatar model={assistant.model} size={30} />}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user