-
-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support of React-Redux 6.0.0 #311
Comments
The code above works with The issue should be related to #188 |
Same problem. I have a wrapped in a
Is it possible to make it work if we wrap Component in |
I tried to pass redux store as a prop to Components, but faced next problem:
I suggest this is because I pass store to a decorated Component, which is exported like this: |
The current workaround is to bridge store in Stage component. import { ReactReduxContext, Provider } from "react-redux";
// later in render:
<ReactReduxContext.Consumer>
{({ store }) => (
<Stage width={window.innerWidth} height={window.innerHeight}>
<Provider store={store}>
<Layer>
{staticTargets.map(t => (
<Target target={t} key={t.id} />
))}
</Layer>
<Layer name="dragging-layer">
{movingTargets.map(t => (
<Target target={t} key={t.id} />
))}
</Layer>
</Provider>
</Stage>
)}
</ReactReduxContext.Consumer> |
Thanks a lot, @lavrton! |
It should be noted that React Redux v6 as is, using the new Context API is being rethought. They are going back to direct subscriptions with a new implementation in another release, possibly v7. |
However, we will still be using the same context mechanism as v6 to make the store available to the components. The difference will be in how the components receive updated store state values. |
FYI: |
The solution @lavrton provide may encounter the issue that child wrapped in |
This final note here.
import { ReactReduxContext, Provider } from 'react-redux';
const Canvas = () => {
return (
<ReactReduxContext.Consumer>
{/* consume store from context */}
{({ store }) => (
<Stage width={window.innerWidth} height={window.innerHeight}>
{/* inject store into context */}
<Provider store={store}>
<SomeCanvasComponents />
</Provider>
</Stage>
)}
</ReactReduxContext.Consumer>
);
}; As @xxlee0927 mentioned:
And I had exactly this issue in the last project. I will try to give the full example of the issue and the solution I used to fix the error. Let us think we have a store: {
wallsIds: ['v1', 'v2'],
walls: {
v1: { fill: 'red' },
v2: { fill: 'blue' }
}
} Now we have a component that creates our drawings. const Canvas = ({ wallsIds }) => {
return (
<ReactReduxContext.Consumer>
{({ store }) => (
<Stage width={window.innerWidth} height={window.innerHeight}>
<Provider store={store}>
<Layer>
{wallsIds.map(id => <Wall id={id} />)}
</Layer>
</Provider>
</Stage>
)}
</ReactReduxContext.Consumer>
);
};
export default connect(store => ({ wallsIds: store.wallsIds }))(Canvas); And we have a const Wall = ({ wall }) => {
return <Rect fill={wall.fill} />
}
export default connect((store, props) => ({ wall: store.walls[props.id] }))(Wall); This issue is that on store update, canvas components connected inside On remove, the store will have no information about wall How we can make sure that properties are in sync?The workaround is simple. We can't use information from the store that we received in {wallsIds.map(id => <Wall id={id} />)}
How to rewrite this code?We can just wrap whole content inside const WallsContainer = ({ wallsIds }) => {
return {wallsIds.map(id => <Wall id={id} />)};
};
export default connect(store => ({ wallsIds: store.wallsIds }))(WallsContainer); And then use it instead: <Stage width={window.innerWidth} height={window.innerHeight}>
<Provider store={store}>
<Layer>
<WallsContainer />
</Layer>
</Provider>
</Stage> I hope I was clear in this large message. If you still have any issues with it, please add your comment. I am going to close the issue for now because I don't think we can do anything else at the current moment. |
This is a known issue of react-konva, see eg. konvajs/react-konva#349 konvajs/react-konva#311 Revert some changes made to drawControl and boardControl reducers.
… api [how] - implement CommentThread, CommentStarter - adopt moment.js to display timestamp - complete remove comment and update comment thread actions - extract canvas component - replace prop drilling with context [reference] According to the following discussion, react-konva <Stage> will influence the Context API: konvajs/react-konva#188 Redux is based on Context API, so it is influenced too konvajs/react-konva#311
Update on this issue. From |
It works. Thank you! The only issue is with hot reload during development. But we are trying to solve it on hmr side |
Tested, It works. Thank you @lavrton |
What if one needs to use values from redux store in Canvas component, for example function MyComponent() {
var state = useSelector(state => state.canvas);
return (
<Canvas onMouseDown={(e) => {
const worldPos = state.scale * mousePos;
console.log(worldPos);}}>
<Provider store={store}>
<Layer>
<WallsContainer />
</Layer>
</Provider>
</Canvas>
);
} ? |
Hello,
I am trying to use latest react@16.7.0 and react-redux@6.0.0 modules with React Konva and I get errors:
It seems that React Konva goes wrong when I use redux connect function with konva shapes.
Reproducible demo: https://codesandbox.io/s/v6v2znvqql
The text was updated successfully, but these errors were encountered: