简体   繁体   中英

How can i populate a DropdownList Options in React without states?

I dont want to use states because this is my 2nd dropdown and its connected to the first one. And i found out when i do this.setstate(...); react is re-render and its breaks my first dropdownlist every selected forms are unselecting. So i want to use this:

const data =[{
   "tablename": "demo_1",
   "segments": "asd"
},
{
   "tablename": "demo_2",
   "segments": "dsa"
}];

And i want something simple like this: 在此处输入图片说明

Is it possible to do that ? I searched but cant find a decent answer.

It sounds to me like your component state doesn't live high enough in your component hierarchy. Try storing state in a parent component, and passing it down to your drop downs as props.

It's not recommend,but if you have to keep the two dropdown,you may try shouldComponentUpdate to prevent the re-render.Here is an example.

 shouldComponentUpdate(nextProps, nextState) {
    if (this.state... == nextState...) {
      return false;
    }
    return true;
  }

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