我正在尝试filtered使用 useRef 即清除反应表组件的状态。ref.current.setState({...}). 这是我的组件的一个片段:
const Customers = (props) => {
const customerTableRef = useRef()
useEffect(() => {
const customerTable = customerTableRef.current
if (customerTable) {
customerTable.setState({ ...customerTable.state, filtered: [] })
console.log("table effect::", customerTable.state)
}
}, [props.selectedDealer])
我在 UI 中有一个选择输入,它绑定到props.selectedDealer我想在用户更改时清除反应表的过滤器props.selectedDealer。react table 组件在组件中不可用,Customers但在层次结构中处于非常低的级别:
Customers > CustomersTable > AppTableWrapper > AppTable > ReactTable.
我正在传递customerTableRefto ReactTable。在开发工具中,我可以看到 ref 被组件选项夸大了,但customerTable.setState({ ...customerTable.state, filtered: []})没有改变ReactTable.