简体   繁体   中英

React cleaner way to lift state up

I've read like 5 SO questions and https://reactjs.org/docs/lifting-state-up.html and I haven't found a better way to do this. I need to toggle a pop-up window from somewhere else in my React project, and their lowest ancestor is App. I need to go through like 20 components across many different files if I want to lift the state up the traditional way (to App, and all the way down to both components). The affected hierarchy looks something like this:

App --> RightColumn --> Search --> ... --> SearchCardEntry --> SearchCardEntryColumn
    --> PopupWrapper --> PopupBook

I think there has to be a better way, especially with bigger projects with thousands of Components.

You can use React Context to easily share data components wide and avoid moving state among way too many layers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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