Skip to content

await fields() How do I use the "preview" property? #1323

Answered by johnlindquist
alkene0005 asked this question in Q&A
Discussion options

You must be logged in to vote

@alkene0005 @ramiroaraujo

Apologies for the late reply, state.value will be an array of the current values. onChange will fire any time a field changes. Also, it might not have been clear there's a fields property on the config object:

let buildPreview = (one, two, three) => {
  setPreview(
    md(`# Current values:
  - one: ${one}
  - two: ${two}
  - three: ${three}    
  
      `)
  )
}

await fields({
  fields: ["one", "two", "three"],
  onInit: (input, state) => {
    buildPreview("", "", "")
  },
  onChange: (input, state) => {
    let [one, two, three] = state.value
    buildPreview(one, two, three)
  },
})

Replies: 1 comment 1 reply

Comment options

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

Answer selected by alkene0005
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