Edit: I was able to connect the child update to a context change with a Redux troubleshooting suggestion when installing { pure: false } , however I needed to add this to all the connected components that the child’s parents want to be updated. It seems strange and ineffective to do this with a lot of components.
First of all, I will describe what my desired end result is before I dive into what I think of the problem.
I want to access settings to adjust the router from within the grandson component of my Route component. There are several links that say that there is no need to synchronize the current route with the store if you do not use “recording, saving and playing back user actions while traveling” , so I have avoided it so far. Dan Abramov states here that it’s normal that they do not synchronize and simply use the route as a source of truth.
Similar questions that do not have answers to my problems: https://stackoverflow.com/a/212877/
Passing through context with <Provider> does not work in connect () based script
Since response-router does not provide the current parameters as a context, I decided to add the current parameter as a context from the Route component. I can access the context right up to the component tree until I reach the Child that was configured with connect () . Initial page rendering gives the child the right context. However, when the context changes, the child is not updated. connect () seems to remove the context link.
Is this the desired connect () behavior? If so, how should the component access the route parameters without synchronization with the repository?
Here is a JSFiddle showing a very minimal scenario when the context is not updated past the “connected” component.
Here is some of my actual code where I send the current route parameter as context from the router component ( /view/:viewSlug ). I tried to install the component { pure: false } in connect , as described in troubleshooting abbreviations but no luck.
Component Parent (App)
class App extends Component { getChildContext() { const { viewSlug } = this.props return { viewSlug } } ... } App.PropTypes = { ... } App.childContextTypes = { viewSlug: PropTypes.string } ... export default connect(mapStateToProps)(App)
Grandchild Container (Day)
import Day from '../components/Day' const mapStateToProps = (state, ownProps) => { ... } export default connect(mapStateToProps)(Day)
Grandchild Component (Day)
class Day extends Component { ... } Day.PropTypes = { ... } Day.contextTypes = { viewSlug: PropTypes.string.isRequired } export default Day
javascript reactjs redux react-router react-redux
Chad fawcett
source share