简体   繁体   中英

React select default value on render doesn't change the selected input value + title on change?

After a couple of trials i have managed to create a React select dropdown with dynamic data for each sector.

Now, i have a problem that i am not able to create a default value on render.

I get all the dynamic values, but i would like to have one default value for instance: Select... i have managed to add one static, but for some reason when i switch from Select Categories the title stays at: Select...

WerkgeverList = () => {
    const werkgeversArray = [];

    const AlleWerkgevers = [
        ...new Set(this.state.opleidingen.map(q => q.opleiding_werkgever)),
    ];

    AlleWerkgevers.map(werkgever => {
        return werkgeversArray.push({ title: werkgever, value: werkgever });
    });

    console.log(werkgeversArray);

    return werkgeversArray;
};

Can someone explain what I am doing wrong?

保持状态中的默认值,然后添加事件侦听器以跟踪更改并更新状态

<select value={current_value} onChange={() => onChangedValueHandler()} >

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM