I have a react-redux application and I am able to receive props inside a component.
This is my componentDidMount() function
componentDidMount() {
this.graphdata = {
dnsCountPlot: {
data: [{
type: 'scatter',
x: this.props.dnsCountPlot.x,
y: this.props.dnsCountPlot.y,
fill: 'tozeroy',
marker: {
color: 'rgb(99, 128, 185)'
}
}],
layout: {
title: '',
xaxis: {
title: 'time'
},
autosize: true
},
config: {
showLink: false,
displayModeBar: true
}
}
};
}
The this.props.dnsCountPlot.x variable is updated every 10 sec and when I print the variable it shows that.
However the this.graphdata variable which contains the this.props.dnsCountPlot.x variable is not being updated. Any idea if this is possible and how to do it?
componentDidUpdate() {
console.log(this.props.dnsCountPlot.x); //Successfully Updated
console.log(this.graphdata); // Doesnt reflect changes of this.props.dnsCountPlot.x
}
the index.js file
const initialState = {
dnsCountPlot : {
x: [],
y: []
}
};
const store = createStore(reducers(initialState));
const history = createBrowserHistory();
startSocket(store);
ReactDOM.render((
<Provider store={store}>
<HashRouter history={history}>
<Switch>
<Route path="/" name="Home" component={Full}/>
</Switch>
</HashRouter>
</Provider>
), document.getElementById('root'));
Thanks.
componentWillReceivePropsto get the new props. Take a look at component lifecyclex,yin your initial state in your redux store as well