While learning react-router v4 I read some of their source code. And as we know they are using current context for passing down router and route info overriding previous/parent route info
React Router is a lightweight, fully-featured routing library for the React JavaScript library. React Router runs everywhere that React runs; on the web, on the server (using node.js), and on React Native.
If you're new to React Router, we recommend you start with the tutorial.
There are many different ways to contribute to React Router's development. If you're interested, check out our contributing guidelines to learn how you can get involved.
Packages
This repository is a monorepo containing the following packages:
Now I was thinking how ReactTraining will make this overriding using new Context API.
From start I used create-react-context polyfill for new context. It works exactly, just change the import.
import{render}from"react-dom";importReact,{createContext}from"react";// import createContext from "create-react-context";
Next we need to create the context. Context has a Consumer and a Provider
const{Provider,Consumer}=createContext();
Provider is used to pass to him some data in value prop
render(){return (<Providervalue={"React is Awesome!"}>
nested content...
</Provider>)}
And Consumer is used to consume that value using render props
render(){return (<Consumer>{(theValue)=>{returntheValue}}</Consumer>// shorthand<Consumer>{theValue=>theValue}</Consumer>)}// output// React is Awesome!