post/

Don't Wait For Me

January 12, 20231 min read

React, Next.js, Supabase, Random

useEffect(() => {
  const staffListener = supabase
    .channel('staff-channel')
    .on(
      'postgres_changes',
      { event: 'INSERT', schema: 'public', table: 'staff' },
      async (payload) => {
        const { id } = payload.new;
        const { staff } = await fetchStaff(id);

        setNewStaff(staff![0]);
      }
    )
    .subscribe();

  return () => {
    supabase.removeChannel(staffListener);
  };
}, []);

useEffect(() => {
  newStaff && setStaffs([newStaff, ...staffs]);
}, [newStaff]);

🎵 Don't wait

Now playing :Not playing any music.