Answer the question
In order to leave comments, you need to log in
How can a method be accessible inside an object via this, but not be accessible from outside by name?
React has a setState() method that can be used inside the object you pass in to instantiate it:
var MyComponent = React.createClass({
getInitialState: function() {
return {
myState: 1
};
},
myMethod: function() {
this.setState({
myState: 1
})
},
render: function() {
return (
<h1>Тест</h1>
);
}
});
Answer the question
In order to leave comments, you need to log in
MyComponent is a constructor function, setState on the prototype. You need to create a component instance.
var instance = ReactDOM.render(<MyComponent />. document.body);
instance.setState({myState: 1});
I don't quite understand - why do you need setState outside?
if you just want to pass parameters - pass them in this form
ReactDOM.render(<MyComponent myState='1' /> , document.body);
....
render: function() {
return (
<h1>Тест { this.props.myState}</h1>
);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question