简体   繁体   English

在项目React.js中设置state管理结构

[英]Setting up the state management structure in the middle of the project React.js

I started the project when I had no experience in React.js, i used prop drilling for entire project.当我没有 React.js 经验时,我开始了这个项目,我在整个项目中使用了道具钻孔。 Now project got complicated as i expected现在项目变得像我预期的那样复杂

So i wanna create state management structure but i don't know how to start.所以我想创建 state 管理结构,但我不知道如何开始。

Can i apply to whole project or could I only use it for the next components?我可以申请整个项目还是只能将其用于下一个组件?

You can easily start using a state management library within parts of your app without needing to refactor the whole app immediately.您可以在部分应用程序中轻松开始使用 state 管理库,而无需立即重构整个应用程序。 This way, you can start using it in new components right away and revisit the older code from time to time and refactor them slowly to clean up prop drilling.这样,您可以立即开始在新组件中使用它,并不时重新访问旧代码并慢慢重构它们以清理道具钻孔。

If you are planning to use React Context, you can follow the pattern recommended here: https://kentcdodds.com/blog/how-to-use-react-context-effectively如果你打算使用 React Context,你可以遵循这里推荐的模式: https://kentcdodds.com/blog/how-to-use-react-context-effectively

I also suggest looking into Redux Toolkit as an alternative to React Context: https://redux-toolkit.js.org/tutorials/quick-start我还建议研究 Redux Toolkit 作为 React Context 的替代品: https://redux-toolkit.js.org/tutorials/quick-start

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM