Closed sruthisripathi closed 6 years ago
Hi!
I believe this happens because the way the Control mounts is outside of the Provider
's component tree. You can see this using React Dev Tools and inspecting how the virtual DOM looks; here the "Data Card" stuff is the Control:
The simplest way to circumvent this would be to connect MapControl
to the Redux store, map the store state to props, then pass them as props to the DataList
component.
A circuitous alternative I'm not 100% sure would work would be: wrap the DataList
in a Provider
, using exactly the same store used by the rest of the app.
@kellyi The first fix you suggested can be used when I just need to get data from redux state. But if I want to dispatch actions from the component rendered inside control, what should I do?
I tried the second fix by Wrapping it in Provider. Still getting the error.
@sruthisripathi so for dispatching actions, you can pass them in as func
props from the parent component too, in a structure like:
<Card handleDispatchAction={arguments => dispatch(actionToDispatch(arguments))}
actionToDispatch
can then be called in the control-wrapped component by calling its handleDispatchAction
prop.
@sruthisripathi Add the <Control>
wrapper inside the DataList
component - that should fix it for you
Version 2.0.0 will support this with React's createPortal
now.
DataList - a connected component
MapControl - Map component with control inside whice DataList (the connected component) is rendered
Gives me the following error
Uncaught Error: Could not find "store" in either the context or props of "Connect(DataList)". Either wrap the root component in a <Provider>, or explicitly pass "store" as a prop to "Connect(DataList)".