作者:胡宸宸 | 来源:互联网 | 2024-10-19 08:14
SoIhaveanappthathasarightsidebarwhosevisibilityistoggledviaabutton.Inthatsidebar
So I have an app that has a right sidebar whose visibility is toggled via a button. In that sidebar there can be one of several things [at a time] - chat, help, search. I was looking at some plain HTML from apps which have a similar feature and noticed that they have all nodes rendered, but are just hidden via CSS.
所以我有一个带有右侧边栏的应用程序,其可见性通过按钮切换。在那个侧边栏中,[一次]可以有几个东西中的一个 - 聊天,帮助,搜索。我正在从具有类似功能的应用程序中查看一些简单的HTML,并注意到它们已经渲染了所有节点,但只是通过CSS隐藏。
Since I need to do the same thing, I was thinking whether this would be a good idea to do with React. But then I realized that React elements have a state which when updated calls the render method. So I can use the state to store both whether the sidebar is opened, and what is inside the sidebar.
由于我需要做同样的事情,我在想是否这对React来说是个好主意。但后来我意识到React元素有一个状态,当更新时调用render方法。因此,我可以使用状态来存储侧边栏是否打开以及侧边栏内部的内容。
Is that the React way of doing things? Is it better to have all nodes rendered even if they are not visible, or is it better to have the nodes rendered on request via state changes?
这是React的做事方式吗?是否更好地渲染所有节点,即使它们不可见,或者通过状态更改请求呈现节点更好?
1 个解决方案