Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Global State management in sveltekit

$
0
0

im using sveltekit with superforms, i want t implement a global state manager using a store, the problem is when i try to access the return from +page.server.ts i get a value of undefined

    add: async ({ request, locals }: { request: Request, locals: any }) => {        const boardAdderForm = await superValidate(request, zod(boardAdderSchema));        if (!boardAdderForm.valid) {            return fail(400, {                boardAdderForm            });        }        try {            const { board_name, board_columns } = boardAdderForm.data;            const newDash = await createDashBoard({                boardName: board_name,                userId: locals.user.id,            });            if (board_columns) {                const catArr = await createCategoryHelper(board_columns, newDash[0].id)                await createCategory(catArr)            }            const board = await getBoardById(newDash[0].id)            return message(boardAdderForm, board)        } catch (e) {            console.log('Error in dashboard: ', e);        }    },

and inside src/lib/components/ui/BoardAdder.svelte

  const { form: Aform, enhance, message } = superForm(boardAdderForm, {    dataType: "json",  });  function sendBoard() {    const board = $message.board    dispatch('boardAdded', board)  }

yet message is undefined, and i have no idea why

and this is how im planning to update the state manager

  function addBoard(event) {    stateManager.addBoard(event.detail)    console.log("🚀 ~ addBoard ~ detail:", event.detail)  }  $: allBoards = $stateManager

this is the repo.thank you for help in advance

i tried updating the store right in the form action but apparently its not the best practice to use stores in server side so that aint an option.

also my apologies if the project structure is out of place, this is my first big projectanyhow thank you for your time


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>