
Link: https://gitlab.com/alex1007/react-test.git
input 里输入名字或者邮箱返回 match 的结果。前几个返回的值即使在 setState 之后也不会消失。
1 maichael May 10, 2018 你的 Contact 子组件写的有问题,直接取 props 就好,为什么存到 state 里。 子组件的 state 从来没变过。 |
2 lbfeng OP @maichael 因为要高亮 keyword 所以还是需要在 constructor 里初始化。getDerivedStateFromProps 解决了 bug https://stackoverflow.com/questions/41233458/react-child-component-not-updating-after-parent-state-change?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa const cOntacts= this.state.result.map((contact, i) => <Contact cOntact={contact} key={i} keyword={this.state.query} />); console.log(contacts); 我的问题是 contacts 这个 array 已经变了,问什么还是有之前的会显示。 |