我知道状态的改变会触发组件的重新呈现.所以我的问题是,在重新渲染过程中,状态更改是否也会卸载功能组件?
main.jsx个
const Fullnote = () => {
const notes = useContext(NotesContext);
const [note, setNote] = useState(INITIAL_VALUE);
const { noteId } = useParams();
useEffect(() => {
notes.forEach(data => {
if (data.id === noteId) setNote(data)
});
return ( () => console.log("return"))
});
return (
<>
......
</>
)
}
在上面代码片段中,我们从上下文中获取对象array.该数组中的每个对象都具有唯一的ID.我们还从url中获取了Note ID.一旦组件挂载useEffect运行,我们就设置与note ID匹配的状态.
will console.log("return") run after setState()?个