In a React + Redux project, I have a connect() ed component that checks user rights through an API fetch. Obtained permissions are stored in the Redux repository.
The component basically looks like <Can check="...">...</Can> , which speaks to our API (through Redux actions) to enable validation. If permission is granted, this.props.children displayed, null otherwise.
To do this, mapStateToProps() computes a passes prop from the authorization data in the repository, which is checked in the <Can /> render() method. I use the ownProps parameter for mapStateToProps() to get the โcheck materialโ and compute the passes flag.
There is a bit of caching going on, so I do not re-read on each mount component, and it basically works. However, sometimes the component will not re-render when the passes prop update is updated to true (it will be displayed after navigation - using the react router) and vice versa, so basically if the component is installed again).
Do the connect() ed components re-render if the result from mapStateToProps() changes? The docs for react-redux connect() talk about this:
If ownProps is specified as the second argument, its value will be the attribute passed to your component, and mapStateToProps will be re-called whenever the component receives new details.
Does this mean that passing to ownProps changes the rendering only for re-rendering, if the props change or in some other way? How can I understand the note regarding memoization / function return from mapStateToProps() , or is it not even related?
thanks
source share