我的代码就像
const [component, setComponent ] = useState( ? )
组件的初始值是多少
if(true)
setComponent(<ComponentA />)
else
setComponent(<ComponentB />)
就我个人而言,我不会将组件存储在状态中,而是存储数据来确定显示的内容。例如:
const [value, setValue] = useState(true)
return (
value ? <ComponentA /> : <ComponentB />
)