Skip to content
Discussion options

You must be logged in to vote

what you need to do is dynamically compute the selected items instead of keeping everything in state. The state only shows what the user has selected, but you can derive something from that during render:

const {data} = useQuery(...) // fetch data from server
const [selectedItems, setSelectedItems] = useState([]);

// here, you filter out items that have been deleted for example
const reallySelectedItems = computeReallySelectedItems(selectedItems, data)

<Select options={data} selected={reallySelectedItems} onChange={(selected)=>setSelectedItems(selected)} />

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@aliakbarazizi
Comment options

@TkDodo
Comment options

Answer selected by aliakbarazizi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants