type Snake = {
data: {
id: string;
isPicked: boolean;
color: string;
}[],
setIspicked:(prevstate:{id:string, isPicked:boolean, color:string}, isPicked:boolean) => void
}
export const useSnake = create<Snake>((set) => ({
data:[
{id:'1', isPicked:false, color:''},
{id:'2', isPicked:false, color:''},
{id:'3', isPicked:false, color:''},
{id:'4', isPicked:false, color:''},
{id:'5', isPicked:false, color:''},
{id:'6', isPicked:false, color:''},
{id:'7', isPicked:false, color:''},
{id:'8', isPicked:false, color:''},
{id:'9', isPicked:false, color:''},
{id:'10', isPicked:false, color:''},
{id:'11', isPicked:false, color:''},
{id:'12', isPicked:false, color:''},
{id:'13', isPicked:false, color:''},
{id:'14', isPicked:false, color:''},
{id:'15', isPicked:false, color:''},
{id:'16', isPicked:false, color:''}
],
setIspicked:(prevstate:{id:string, isPicked:boolean, color:string}, Bool:boolean) => {
}
}))
i want to find object === prevstate from setIspicked props and update his isPicked from isPicked props but i dont know how use map inside set()
setIspicked:(prevstate:{id:string, isPicked:boolean, color:string}, Bool:boolean) => {
set(state => ({data: state.data.map(res => res === prevstate? {id:prevstate.id, isPicked:Bool, color:prevstate.color}:res)}))
}