Javascript 如何在react native';什么州?
我在浏览时遇到了一个经典的this.setState调用,它没有合并到带有标签的对象中Javascript 如何在react native';什么州?,javascript,react-native,syntax,ecmascript-6,Javascript,React Native,Syntax,Ecmascript 6,我在浏览时遇到了一个经典的this.setState调用,它没有合并到带有标签的对象中 constructor(props) { super(props); this.state = { films: [], query: '' }; } componentDidMount() { fetch(`${API}/films/`).then(res => res.json()).then((json) => {
constructor(props) {
super(props);
this.state = {
films: [],
query: ''
};
}
componentDidMount() {
fetch(`${API}/films/`).then(res => res.json()).then((json) => {
const { results: films } = json;
this.setState({ films });
});
}
我期待着this.setState调用看起来像
this.setState({ films: films });
哪里有代码/文档说明允许使用这种语法糖?这是纯javascript特性还是React特性
相关研究
这感觉类似于,但“相反”
我还仔细检查了API调用是否确实返回一个数组,如
"results": [ ... ]
所以它不像这个.setState({films})
实际上具有形式this.setState({films:actual_object})代码>它来自
另请参见语法糖。这是ES2015
this.setState({ films });
// is the same as:
this.setState({ films: films });