Zustand question in next js

i have this code
export const useTaskStore = create<State & Actions>()(
persist(
set => ({
tasks: [],
draggedTask: null,
addTask: (title: string, description?: string) =>
set(state => ({
tasks: [
...state.tasks,
{ id: uuid(), title, description, status: 'TODO' }
]
})),
dragTask: (id: string | null) => set({ draggedTask: id }),
}),
{ name: 'task-store', skipHydration: true }
)
)
export const useTaskStore = create<State & Actions>()(
persist(
set => ({
tasks: [],
draggedTask: null,
addTask: (title: string, description?: string) =>
set(state => ({
tasks: [
...state.tasks,
{ id: uuid(), title, description, status: 'TODO' }
]
})),
dragTask: (id: string | null) => set({ draggedTask: id }),
}),
{ name: 'task-store', skipHydration: true }
)
)
and
export default function Column({
title,
status
}: {
title: string
status: Status
}) {
const tasks = useTaskStore(state => state.tasks)
const filteredTasks = useMemo(
() => tasks.filter(task => task.status === status),
[tasks, status]
)
const updateTask = useTaskStore(state => state.updateTask)
const dragTask = useTaskStore(state => state.dragTask)
const draggedTask = useTaskStore(state => state.draggedTask)
useEffect(() => {
useTaskStore.persist.rehydrate()
}, [])

const handleDrop = (e: React.DragEvent<HTMLDivElement>) => {
if (!draggedTask) return
updateTask(draggedTask, status)
dragTask(null)
}
return (
<section className='h-[600px] flex-1'>
<div
className='mt-3.5 h-full w-full rounded-xl bg-gray-700/50 p-4'
onDrop={handleDrop}
onDragOver={e => e.preventDefault()}
>
<div className='flex flex-col gap-4'>
{filteredTasks.map(task => (
<Task key={task.id} {...task} />
))}

{filteredTasks.length === 0 && status === 'TODO' && (
<div className='mt-8 text-center text-sm text-gray-500'>
<p>Create a new task</p>
</div>
)}
</div>
</div>
</section>
)
}
export default function Column({
title,
status
}: {
title: string
status: Status
}) {
const tasks = useTaskStore(state => state.tasks)
const filteredTasks = useMemo(
() => tasks.filter(task => task.status === status),
[tasks, status]
)
const updateTask = useTaskStore(state => state.updateTask)
const dragTask = useTaskStore(state => state.dragTask)
const draggedTask = useTaskStore(state => state.draggedTask)
useEffect(() => {
useTaskStore.persist.rehydrate()
}, [])

const handleDrop = (e: React.DragEvent<HTMLDivElement>) => {
if (!draggedTask) return
updateTask(draggedTask, status)
dragTask(null)
}
return (
<section className='h-[600px] flex-1'>
<div
className='mt-3.5 h-full w-full rounded-xl bg-gray-700/50 p-4'
onDrop={handleDrop}
onDragOver={e => e.preventDefault()}
>
<div className='flex flex-col gap-4'>
{filteredTasks.map(task => (
<Task key={task.id} {...task} />
))}

{filteredTasks.length === 0 && status === 'TODO' && (
<div className='mt-8 text-center text-sm text-gray-500'>
<p>Create a new task</p>
</div>
)}
</div>
</div>
</section>
)
}
so, here i can add task and drag and drop, but if i delete
useEffect(() => {
useTaskStore.persist.rehydrate()
}, [])
useEffect(() => {
useTaskStore.persist.rehydrate()
}, [])
and
skipHydration: true
skipHydration: true
still works the same, why ?
2 Replies
Eve
Eveβ€’2mo ago
FYI when you post blocks of code, it's helpful if you put js or ts immediately after the opening ``` to enable syntax highlighting. Makes it much easier for anyone to parse what you're dealing with
<DxD/>
<DxD/>OPβ€’2mo ago
done thx @π“”π“‚π’Ύπ“π“Ž (Solid fangirl) can u give me a hint for my pb?
Want results from more Discord servers?
Add your server