Assume I use desired provider in my app, let name it MyProvider
and wrapp my app with it. And that provider must take data1
and data2
as props:
const data1 = store.getState().data1;
const data2 = "some data";
<Provider store={store}>
<Myprovider data1={data1} data2={data2}>
<App/>
</Myprovider>
</ Provider>
So data1
is retrieved from state, and data2 is predefined data. When data1
is changed (I mean when some actions are dispatched and some changes on state's data1
happen, provider doesn't detect it).
So what comes to my mind is to create wrapper for Myprovider
, lets call it ConnectedMyprovider
that will be connected to redux store, and will pass data1
and data2
to Myprovider
as props.
Code for ConnectedMyprovider
would be something like:
import {connect} from 'react-redux';
import {MyProvider} from 'MyProvider';
function mapStateToProps(state, ownProps) {
const {data1} = state.data1;
const data2 = ownProps.data2;
return {data1: data1, data2: data2};
}
export default connect(mapStateToProps, null)(MyProvider);
And then, wrapping my app becomes as:
const data2 = "some data";
<Provider store={store}>
<ConnectedMyProvider data2={data2}>
<App/>
</ConnectedMyProvider>
</ Provider>
It ends up with error Make sure your <MyProvider> is set up correctly.
No data2
provided. Does anyone know how to do this?