Skip to content

Fetching data and formatting it #107

Closed Answered by gustavoguichard
deanfields asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @deanfields , thanks for reaching out! Glad to know you've been using DFs and Remix 🔥

I don't know if there's a best way but here is how I'd model it:

import { makeDomainFunction as mdf, map } from "domain-functions"

const fetchLists = mdf(z.object({ withTasks: z.boolean().optional() }), UserSchema)(
  async ({ withTasks = false }, { sessionId }) => {
    // I'd put the body of fetchListsByUserId function here instead of creating another abstraction
    // IMO the DF is the place to put the core of the business logic
    // Excuse me for the pseudo code below
    const response = await fetch(`${API}/lists/${sessionId}?withTasks=${withTasks}`)
    const json = await response.json()
    r…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@deanfields
Comment options

@gustavoguichard
Comment options

Comment options

You must be logged in to vote
1 reply
@deanfields
Comment options

Answer selected by diogob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants