I have created a select usign react-select, with a button inside. I use this button to call another page in the api to obtain other 20 values.
const [pageNumber, setPageNumber] = useState(0)
useEffect(() => {
props.getComunes(pageNumber);
}, [pageNumber])
const comunes = Comunes.map(comune => {
return ({ value: comune.comCod, label: comune.comDes })
})
const addValue = () => {
setPageNumber(pageNumber + 1)
}
const SelectMenuButton = (props) => {
console.log("props ", props)
return (
<components.MenuList {...props}>
{props.children}
<button onClick={() => addValue()}>Add new element</button>
</components.MenuList >
)
}
return(
//...
<AvGroup>
<Label id="comCodLabel" for="comCod">
Select
</Label>
<AsyncSelect
options={comunes}
placeholder='Start typing'
components={{ MenuList: SelectMenuButton }} />
</AvGroup>
)
const mapDispatchToProps = {
getComunes
}
Now my problem is that in this way the list is replaced with the new list ( so at the beginning I have 20 first values, if I click on button I have the second 20 values, while I would to obtain 40 result in the list ).
How can I do to concat the new list and not replace it?