Skip to content

How to load data into dynamically created forms in a page with multiple forms? #2562

Answered by maddhruv
gidsdangil asked this question in General
Discussion options

You must be logged in to vote

Hey @gidsdangil there can be multiple ways of doing this - loading some data (async) and then rendering the form. These are some I would consider if I fall into such a scenario

  1. fetch data and render
// load the data async and set a state to track that the data has been loaded 
fetch('data.json').then(() => setHasData(true))

{
    data && <RenderForm data={data} />
}

// RenderForm
const form = useFormik({
    initialValues: props.data
})
  1. if you already know about the structure of the form (which I think you do) and have some default data to show to the user
// initialize the form with the default initialValues
const form = useFormik({
    initialValues
})

// fetch the async data and…

Replies: 1 comment 2 replies

Comment options

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

@GustavoJava
Comment options

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