相关文章推荐
耍酷的芹菜  ·  [Python] async def & ...·  2 月前    · 
聪明的作业本  ·  Example C Program: ...·  2 年前    · 
失望的扁豆  ·  频谱图 - 知乎·  2 年前    · 

RFC: async defaultValues #2492

@bluebill1049

Description

Summary

The current status of setting defaultValues from async data source is using reset :

useEffect




    
(() => {
  reset({
     firstName: 'test',
});

honestly, this is probably not a pretty and clean approach... a few weeks before we had a feature request regarding async defaultValues : #2335

Proposal Solutions

  • defaultValues accept Promise , and promise will get resolve after useEffect , although I do have concern over the confusion which prop support both object and Promise .
  • const { formState: { isLoading } } = useForm({
      defaultValues: async () => ({ firstName: 'test' })
      // defaultValues: new Promise()
    }, [])

    happy to discuss more options on the table too.