Closed ricaralan closed 5 years ago
but I couldn't connect it
What doesn't work? Are there any errors in the console?
Thanks for answering @Ni55aN. I get the following error when I try to connect a custom node.
Could not find "store" in the context of "Connect(CustomMessageNode)". Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to Connect(CustomMessageNode) in connect options
With the following code
import React from "react";
import { Node, Socket } from "rete-react-render-plugin";
import classnames from 'classnames';
import { library } from '@fortawesome/fontawesome-svg-core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faAlignLeft, faTrash, faClone } from '@fortawesome/free-solid-svg-icons';
import { connect } from "react-redux";
import './style.css';
library.add(faAlignLeft);
library.add(faTrash);
library.add(faClone);
class CustomMessageNode extends Node {
render() {
const { node, bindSocket } = this.props;
const { outputs, inputs, selected } = this.state;
return (
<div className={`node-container message ${selected}`}>
<div className="top-controls">
<div className="top-controls-item">
<FontAwesomeIcon icon="clone" />
</div>
<div className="top-controls-item">
<FontAwesomeIcon icon="trash" />
</div>
</div>
<div className="title">
{inputs.filter(input => input.key === 'COMPONENT_SOCKET_IN').map(input => (
<div className={classnames('socket-component-container top-unique-in',{
used: input.connections.length,
})} key={input.key}>
<Socket
type="input"
socket={input.socket}
io={input}
innerRef={bindSocket}
/>
</div>
))}
{node.name}
</div>
<div className="body">
<div className="message-item empty-message">
<FontAwesomeIcon icon="align-left" />
<br/>
Da clic para agregar mensaje
</div>
</div>
<div className="footer">
{outputs.filter(output => output.key === 'COMPONENT_SOCKET_OUT').map(output => (
<div className={classnames('socket-component-container bottom-unique-out',{
used: output.connections.length,
})} key={output.key}>
<Socket
type="input"
socket={output.socket}
io={output}
innerRef={bindSocket}
/>
</div>
))}
</div>
</div>
);
}
}
const mapStateToProps = state => ({
...state
});
const mapDispatchToProps = dispatch => ({
});
export default connect(mapStateToProps, mapDispatchToProps)(CustomMessageNode);
I think the error originates here.
https://github.com/retejs/rete/blob/master/src/editor.ts#L23
The containers are of type HTMLElement and not ReactElement so it does not insert the nodes within the context of the provider.
https://github.com/retejs/rete/blob/master/src/view/index.ts#L34
The containers are of type HTMLElement and not ReactElement so it does not insert the nodes within the context of the provider.
It is expected since the core knows nothing about React. Try to pass the store directly to your custom component
I already did it and I get the error that I specified here
https://github.com/retejs/rete/issues/374#issuecomment-536452628
Thanks for answering @Ni55aN. I get the following error when I try to connect a custom node.
Could not find "store" in the context of "Connect(CustomMessageNode)". Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to Connect(CustomMessageNode) in connect options
With the following code
import React from "react"; import { Node, Socket } from "rete-react-render-plugin"; import { connect } from "react-redux"; class CustomMessageNode extends Node { ....... } const mapStateToProps = state => ({ ...state }); const mapDispatchToProps = dispatch => ({ }); export default connect(mapStateToProps, mapDispatchToProps)(CustomMessageNode);
I already did it
I only see that you are trying to "connect" the store, but store is missing in context.
Try something like this
editor.use(ReactRenderPlugin, {
component: props =>(<Provider store={storeApp}>
<CustomMessageNode {...props}/>
</Provider>);
});
@Ni55aN you're right, that's how it works.
thank you.
First of all, AMAZING project!
rete v1.3.0 rete-react-render-plugin v0.2.0 react v16.9.0 redux v4.0.4 react-redux v7.1.1
I tried to connect retejs with redux but I couldn't connect it. Do you have any connection example?
My code is as follows:
Index.js
App.js
editor.js