[英]Passing data to top-level React component
ReactJS newb question. ReactJS newb问题。 I'm sure this is obvious, but I can't find the place in the doc. 我确定这很明显,但是我无法在文档中找到该位置。
I have a React component, which is rendered like so: 我有一个React组件,其呈现方式如下:
React.render(
<MyComponent data="{myVar}" />,
document.getElementById("element")
);
When myVar changes, it doesn't appear to automatically call the componentWillReceiveProps
method on MyComponent, which I assumed it would. 当myVar更改时,它似乎并没有自动调用MyComponent上的componentWillReceiveProps
方法,而我认为会那样。 That's fine, but how do explicitly tell the component to update? 很好,但是如何明确指示组件进行更新? I gather setState() is done internally within the component. 我收集setState()是在组件内部完成的。
Okay, found it: looks like setProps
was added for this very purpose, eg 好的,找到它:看起来为此目的添加了setProps
,例如
var myComponent = React.render(
<MyComponent data={myVar} />,
document.getElementById("element")
);
// ... later on ...
myComponent.setProps({ data: 'newData' });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.