未调用componentDidUpdate函数

时间:2020-07-13 10:02:20

标签: reactjs react-component

我已经创建了一个React组件以在内部渲染另一个组件。当我更改父组件中的select元素时,在子组件中不会调用componentDidUpdate函数

component1:

let ExtraParam = [];

const handleChange = (e) => {
    ExtraParam[e.target.name] = e.target.value;
}
            
const Flights = () => {
    return (
        <div>
            <div className="row">
                <div className='col-6 col-md-3 mt-5'>
                    <select onChange={handleChange} name="age" className="browser-default custom-select">
                        <option>Choose your option</option>
                        <option value="1">Option 1</option>
                        <option value="2">Option 2</option>
                    </select>
                </div>
            </div>
        <Datatable Api='/api/Flights' Columns={columns} extraParam {ExtraParam} />
        </div>
    )
}

component2:

componentDidUpdate(prevProps) {
    if (this.props.extraParam !== prevProps.extraParam)
    {
        console.log('changed');
    }
}

0 个答案:

没有答案