0
votes

I'm trying to create a list of select with one option but when changing any one they all changed, i want to handle them one by one. Im using map in order to get the data and display it using useState.

enter image description here

Here is the code below :

    const positions = patients.data.map((element) => {
        return element.first_name + " " + element.last_name;
    });
    const [Position, setPosition] = useState(positions[0]);

  const [serviceList, setServiceList] = useState([{service:""}]);
    const handleServiceAdd = () =>{
        setServiceList([...serviceList,{service:""}])
    }

    const handleServiceRemove = (index) => {
        const list = [...serviceList];
        list.splice(index,1);
        setServiceList(list);
    }
2
Can you include the render() or return() functions' values as well? - Mehrdad Moradi
more code please - Shaded

2 Answers

0
votes

If you are using styled components, place them before writing the function that renders your component.

For example, your component name is "Component", your code shouldn't look like:

const Component => {
    const YourStyledComponent = styled.div``

    return(...) 
}

But it should look like:

const YourStyledComponent = styled.div``

const Component => {  
    return(...)
}

Why ? Because everytime you will change one state, everything inside your component will rerender

-2
votes

can you show your entire code? I want to see how you call this function