useRecoilCallback not updating state on click

458 Views Asked by At

Why is this code not working?

The updateCurrentSong is not even running on click


    const currentSong = useRecoilValue(currentSongState)

    const updateCurrentSong = useRecoilCallback(({snap, set}) => () => {
        set(currentSongState, prev => ({...prev, playing: !currentSong.playing}))
    }, [currentSong])

    return (
        <div onClick={updateCurrentSong()} >
   

1

There are 1 best solutions below

0
On

I know this is late, but I think it's because you have parentheses in your onClick attribute. I believe it should be like this:

<div onClick={updateCurrentSong}>
...
</div>