我已经设置了沙箱来展示如何做到这一点.
I've set up a sandbox to showcase how you can do this.
- 布尔值设置为
false
的初始化状态
- 基于此布尔值有条件地渲染组件;因此最初该组件现在将显示在DOM上
- 在执行某些操作(
onClick
)时,将setState
放在布尔值上以true
- 状态更改后,组件将重新呈现,现在将显示隐藏的组件(因为布尔值已设置为
true
)
- Initialise state with a boolean set to
false
- Render the component conditionally based on this boolean; so initially the component will now show up on the DOM
- On some action (
onClick
), setState
on the boolean to true
- The component will re-render since the state changed and will now show the hidden component (since the boolean has been set to
true
)