R
Reactiflux

πŸŽƒ Spookyberb πŸŽƒ – 12-59 Nov 3

πŸŽƒ Spookyberb πŸŽƒ – 12-59 Nov 3

Sβ›„Snowberbβ›„11/3/2022
Having a function at the parent level, is it possible to pass from the child a value parameter to the function while also passing another parameter from the parent? I want to pass a limit param from the parent, and a value param from the child
const isValid = (value, limit = 25) => value.length <= limit;

<ControlledInput validationFunction={isValid} />
const ControlledInput = ({ control, name, label, validationFunction }) => (
<Controller
...
onValueChange={(val) => {
if (validationFunction(val)) {
onChange(val);
}
}}
...
/>
);
const isValid = (value, limit = 25) => value.length <= limit;

<ControlledInput validationFunction={isValid} />
const ControlledInput = ({ control, name, label, validationFunction }) => (
<Controller
...
onValueChange={(val) => {
if (validationFunction(val)) {
onChange(val);
}
}}
...
/>
);
LLouis11/3/2022
Yeah, you can change <ControlledInput validationFunction={isValid} /> to
<ControlledInput validationFunction={(value) => isValid(value, limit)} />
<ControlledInput validationFunction={(value) => isValid(value, limit)} />
Assuming limit is available in scope from the parent there meowthumbsup
Sβ›„Snowberbβ›„11/3/2022
damn how does that work? oooo okay thank you!
LLouis11/3/2022
It’s just a callback function so you can receive the value from the child and call isValid with it and whatever is in scope in the parent No worries meowthumbsup
UUUnknown User11/4/2022
Message Not Public
Sign In & Join Server To View

Looking for more? Join the community!

R
Reactiflux

πŸŽƒ Spookyberb πŸŽƒ – 12-59 Nov 3

Join Server