react-step-progress
react-step-progress copied to clipboard
Validator and state in React.
Hi, I implemented step validator returning a hook state. But when the function is called, triggered by the "next" button, the state used in the validator is an old one, corresponding to the state during Its declaration in useEffect rule.
It seems the validation implementation doesn't support the changes state related to a hook, and only allows Its scope logic.
Do you know how I can use validator to return a boolean depending of state ? For instance return a variable passed by child component.
Thanks for help and don't hesitate if you need some payloads.
I've experienced the same issue, what solved it for me was using useRef
for example
const [isValid, setIsValid] = useState(false)
const curIsValid = useRef(isValid);
curIsValid.current = isValid;
const steps = [
...
{
label: 'Test',
validator: () => curIsValid.current,
}
]
I've experienced the same issue, what solved it for me was using
useRef
for exampleconst [isValid, setIsValid] = useState(false) const curIsValid = useRef(isValid); curIsValid.current = isValid; const steps = [ ... { label: 'Test', validator: () => curIsValid.current, } ]
Thank you. I've been working with this library and spent several hours looking for an answer.