Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

useTypedController.d.ts does not account for passing of refs #28

Open
damienteo opened this issue Jan 6, 2021 · 0 comments
Open

useTypedController.d.ts does not account for passing of refs #28

damienteo opened this issue Jan 6, 2021 · 0 comments

Comments

@damienteo
Copy link

damienteo commented Jan 6, 2021

Under useTypedController.d.ts:

  render?: ((props: {
        onChange: (...event: any[]) => void;
        onBlur: () => void;
        value: import("./types").DeepPathValue<UFieldValues, TFieldName>;
    }) 

Only onChange, onBlur, and value are allowed to be passed as props

The issue comes due to the issue: react-hook-form/react-hook-form#3411

I am attempting to render MUI TextInput in TypedController.

           <TypedController
             name="price_ceil"
             defaultValue=""
             render={(props) => (
               <TextInput
                 label="When the price has risen to"
                 variant="outlined"
                 type="number"
                 inputProps={{
                   'data-testid': 'Min-Price-Input',
                 }}
                 error={!!errors.price_ceil}
                 helperText={errors.price_ceil?.message}
                 {...props}
               />
             )}
           />

However, I am receiving the warning that Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?.
The fix is to pass a ref to InputRef when rendering TextInput.

However, due to the typing in useTypedController, I get the typing error Property 'ref' does not exist on type '{ onChange: (...event: any[]) => void; onBlur: () => void; value: string | number | undefined; }'.

Will there be any issues with passing ref as well in the render for TypedController?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant