Skip to content

x-reactions 自定义使用请教 #1461

Answered by liuweiGL
prgrmrwy asked this question in Q&A [2.x]
Discussion options

You must be logged in to vote

可能你已经解决问题了,但还是建议你把有联动的字段封装成一个组件来使用:

import { useEffect } from 'react'

import useRequest from '@ahooksjs/use-request'
import { useForm } from '@formily/react'

type MockData = {
  a: number
  b: boolean
  c: string
}

const api = (params: any) => {}

const AsyncSelect = () => {
  const form = useForm<MockData>()

  const { a, b, c } = form.values

  const { data, run } = useRequest(api, {
    manual: true
  })

  useEffect(() => {
    run({
      a,
      b,
      c
    })
  }, [a, b, c, run])

  return (
    <Select>
      {data.map(item => (
        <Option />
      ))}
    </Select>
  )
}

export default observer(AsyncSelect)

Replies: 4 comments 15 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
15 replies
@prgrmrwy
Comment options

@prgrmrwy
Comment options

@janryWang
Comment options

@prgrmrwy
Comment options

@janryWang
Comment options

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