在手势期间,我想要更新组件中的文本。如果我更新状态,它的工作速度就不够快。所以我想像setNativeProps一样直接更新这个组件的内容。是否可以使用原生react?
发布于 2015-10-20 00:16:33
您可以使用refs直接操作组件。在JSX中:
<Text ref='myTextComponent'>Test Text</Text>然后,您可以使用:
doThing: function(value) {
this.refs.myTextComponent.setNativeProps({
opacity: value
});
},不过要小心,建议您不要经常使用它,因为它可能会造成性能瓶颈。当使用不当时,它也是针对React状态的反模式。
文档可以在这里找到:https://facebook.github.io/react-native/docs/direct-manipulation.html#content
https://stackoverflow.com/questions/33195724
复制相似问题