Answer the question
In order to leave comments, you need to log in
How to set props value dynamically?
There is a dynamicData variable that changes every 3 seconds. How to set the value of the variable in props or in another way so that the component is automatically rendered when it changes? Code jsfiddle.net/jv69s81h/4/
Answer the question
In order to leave comments, you need to log in
Use state instead of props :
var Hello = React.createClass({
getInitialState: function() {
return { test: 0 };
},
componentWillMount: function() {
setInterval(() => {
var dynamicData = (Math.random() * 100).toFixed(0);
this.setState({ test: dynamicData });
}, 3000);
},
render: function() {
return <h2>{this.state.test}</h2>;
}
});
ReactDOM.render(
<Hello />,
document.getElementById('container')
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question