Qtr No. 213, New Town Yehlanka Indore 454775
Consider the following code Snippet:
const withValidation = (WrappedComponent, validationFn) => {
return function WithValidation(props) {
const [valid, setValid] = React.useState(false);
const validate = () => {
setValid(validationFn());
};
return (
<WrappedComponent
valid={valid}
validate={validate}
{...props}
/>
);
};
};
const FormComponent = ({ valid, validate }) => (
<div>
<form>
{/* ... form fields ... */}
</form>
<button onClick={validate}>Validate</button>
{valid ? <p>Form is valid</p> : <p>Form is invalid</p>}
</div>
);
const ValidatedFormComponent = withValidation(FormComponent, () => true);
What does the withValidation HOC do for the FormComponent?
It adds form validation logic to the FormComponent.
It creates a new form component with validation capabilities.
It demonstrates how to implement a custom form validation hook.
It adds form validation logic to a component using the provided validation function.
To get all Infosys Certified React Expert Exam questions Join Group https://bit.ly/infy_premium_group
We're passionate about offering best placement materials and courses!! A one stop place for Placement Materials. We daily post Offcampus updates and Placement Materials.
Qtr No. 213, New Town Yehlanka Indore 454775
admin@prepflix.in