我试图在我的反应钩子中使用 useEffect() 来更新我的道具改变时的状态。但是有一个延迟,并且只有在我再次单击我的钩子中的一个元素后才会触发 useEffect 。我对使用钩子相当陌生,任何帮助将不胜感激。谢谢
function ImageOrderSelect (props) {
const [clicked, setClicked] = useState(false)
const [options, setOptions] = useState(props.options)
const [current, setCurrent] = useState(props.current)
useEffect(() => {
setCurrent(props.current)
}, [props.current])
if(!clicked){
return (
<div className="image-order-select-icon" onClick={() => setClicked(!clicked)}>
<FontAwesomeIcon size="lg" icon={faCircle} />
<p>{current}</p>
</div>
)
} else if(clicked){
return (
<div className="image-order-select">
{optionsList}
</div>
)
}
}