简体   繁体   中英

How many context provider we should have in the page React js

Is it good to have the context provider according to the page wise. For example Dashboard have one Provider called Dashboard Provider And test have another provider called Test Provider. Or it is good to have single big provider for all the different page.

According to the React docs for context .

Context is primarily used when some data needs to be accessible by many components at different nesting levels. Apply it sparingly because it makes component reuse more difficult.

If you only want to avoid passing some props through many levels , component composition is often a simpler solution than context .

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