![react router dom v4 context react router dom v4 context](https://marmelab.com/images/blog/code-splitting/vendorChunkStep1.png)
![react router dom v4 context react router dom v4 context](https://res.cloudinary.com/practicaldev/image/fetch/s--8iUfUnKn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/uux1yxcq6yukpwx0i9dx.png)
How do you provide values to inputs? How do you change the active tab? How do you add another row to this table? You setState and render a component. In other words, by using components and attempting to completely hide our imperative API, every question about routing can be answered by your app instead of our docs. Are you using redux? Navigate with dispatch, component state? navigate with setState.
React router dom v4 context code#
It's the same reason we use controlled inputs instead of refs and DOM API like value or setAttribute.īy using Just Components™, we have effectively pushed all imperative code up to your app's opinions on state management. Using ansitionTo we now would have two ways to change the state of an app. The idea behind hiding all of our imperative API behind components is an effort to push all changes to state in your app (including the URL) to setState. The whole point of setState is to change the state of your app and render something else. Otherwise there would would be no way to set state!
![react router dom v4 context react router dom v4 context](https://themeselection.com/wp-content/uploads/2020/11/React-Material-Admin-Material-UI-Dashboard-Template.png)
So I don't think it's like saying there should be no event handlers. SetState and forceUpdate are the only ones that we are encouraged to use, and even forceUpdate should be used rarely, which leaves us with effectively only one imperative method: setState. Once you're rendering, react gives you 4 imperative methods: setState, forceUpdate, replaceState, and isMounted. This is just as saying that there should be no event handlers in React, IMHO.