Next.js Discord

Discord Forum

Losing reactivity if writing directly to JSON file

Unanswered
Great Skua posted this in #help-forum
Open in Discord
Great SkuaOP
I have a JSON file
import wishlistData from '@/data/wishlist.json';

And I have an array
const [wishlistArr, setWishlistArr] = useState<IWishlist[]>(wishlistData);

Whenever I call the setWishlistArr, the component will be re-rendered.

But now I want to change the way I create new wishlist a bit.
Whenever I receive new wishlist, I want to add it directly to the json file, but it means that im losing the reactivity because I won't use the set function.
How do I fix that?

0 Replies