I have a two selection list from where i can select the value
list one= "A", "B"
list two = "C", "D", "E", "F"
I have a state in react
const [filterTags, setFilterTags] = useState({ one: [], two: [] });
I can pass one val at a time from any of the list in updateValue(val)
I need to update the filterTags in such a vay that if its val is from list one that is A or B it should update the state like this
{one:["A"]: two:[]}
const updateValue = (val) => {
if (val === 'A' || val === 'B') {
setFilterTags({ one: val });
} else {
setFilterTags({ ...filterTags, two: val });
}
};
if I pass A C C D B A E C one by one it should update the array with the unique values and the output should be
{one:["A"]: two:[]} //passing A
{one:["A"]: two:["C"]} //passing C
{one:["A"]: two:["C"]} // same since C is already there in two on passing C
{one:["A"]: two:["C","D"]} //passing D
{one:["A","B"]: two:["C","D"]} //passing B
{one:["A","B"]: two:["C","D"]} //same since A is already present in one on //passing A
{one:["A","B"]: two:["C","D","E"]} //passing E
{one:["A","B"]: two:["C","D","E"]}// final output on passing C
it should update the respective element with unique values right now the above code can just update a single value