ant-design FormItemInputContext is always an empty object in a customized form control

vh0rcniy  于 4个月前  发布在  其他
关注(0)|答案(2)|浏览(104)

https://stackblitz.com/edit/react-vhhuml?file=src%2Findex.js,src%2FApp.js

Steps to reproduce

  1. Type anything in input
  2. Watch the changes in the console

What is expected?

I'm writing a customized form control. I found that we are using the FormItemInputContext to share the context from the Form.Item to the children, so I want to use the FormItemInputContext to get the contextStatus , hasFeedback , feedbackIcon ,... but it's always an empty object. So how to use it in a customized form control?

What is actually happening?

The context is always an empty object
| Environment | Info |
| ------------ | ------------ |
| antd | 4.21.0 |
| React | 17.0.2 |
| System | Windows |
| Browser | Chrome |

hs1rzwqc

hs1rzwqc1#

same issue here
need help

lbsnaicq

lbsnaicq2#

import { FormItemInputContext } from 'antd/es/form/context';

...

const context = useContext(FormItemInputContext);

import source should be 'antd/es/form/context'

相关问题