New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why no wrapped Text, TextArea, Checkbox, Radio, RadioGroup and Select is not exported? #25
Comments
Text
, TextArea, Checkbox, Radio, RadioGroup and Select is not exported?
Text
, TextArea, Checkbox, Radio, RadioGroup and Select is not exported?
Im confused as to what you are looking for.. I think what you want is to use the |
Yes but const CustomInput = ({ fieldApi, fieldState, customProp, ...props }) => {
const {
value
} = fieldState;
const {
setValue,
setTouched
} = fieldApi;
const {
onChange,
onBlur,
forwardedRef,
...rest
} = props;
return (
<div className={fieldState.error ? 'error' : ''}>
{/*...*/}
<input
{...rest}
ref={forwardedRef}
value={!value && value !== 0 ? '' : value}
onChange={e => {
setValue(e.target.value);
if (onChange) {
onChange(e)
}
}}
onBlur={e => {
setTouched();
if (onBlur) {
onBlur(e)
}
}}
/>
{/*...*/}
</div>
)
};
export default asField(CustomInput); Do you see how many code can be reuse when you export |
Im sorry but i dont? |
Maybe an example would help |
Also it looks like you have two issues out for the same thing.. can we delete one and consolidate. |
Ok, I want implement Bootstrap input with const BootstrapInput = ({ fieldApi, fieldState, className, ...props }) => {
const {
value,
error
} = fieldState;
const {
setValue,
setTouched
} = fieldApi;
const {
onChange,
onBlur,
forwardedRef,
...rest
} = props;
return (
<React.Fragment>
<input
{...rest}
ref={forwardedRef}
value={!value && value !== 0 ? '' : value}
className={cn(['form-control', className, error ? 'is-invalid' : null])}
onChange={e => {
setValue(e.target.value);
if (onChange) {
onChange(e)
}
}}
onBlur={e => {
setTouched();
if (onBlur) {
onBlur(e)
}
}}
/>
{ error && (
<div className="invalid-feedback">
{error}
</div>
) }
</React.Fragment>
)
};
export default asField(BootstrapInput); It is 46 lines. But when I will be can reuse const BootstrapInput = ({ fieldState: {error}, className, ...props }) => {
return (
<React.Fragment>
<BasicText
{...props}
className={cn(['form-control', className, error ? 'is-invalid' : null])}
/>
{ error && (
<div className="invalid-feedback">
{error}
</div>
) }
</React.Fragment>
)
};
export default asField(BootstrapInput); Only 17 lines! Do you see advantage? Thanks only by export |
Ok you may have convinced me however i want to try somthing before i do this.. im not at my comp atm but will be in an hour and i can let ya know |
Ok so technically this is already achievable:
|
It's works but see please: you create new component in each render! You lost any React's optimizations! |
Ok i think you have convinced me |
This is in the latest version! Will add better docs soon but you can check out the custom inputs section that i added |
I want to implement custom input. It may be very helpful if the no wrapped version of
Text
and etc. will be exported. Then I will be able to reuse no wrappedText
and implement custom input as kind of:The text was updated successfully, but these errors were encountered: