Consider the following Code Snippet
const withLoading = (WrappedComponent) => {
return function WithLoading(props) {
const [loading, setLoading] = React.useState(true);
React.useEffect(() => {
setTimeout(() => {
setLoading(false);
}, 2000);
}, []);
return loading ? <p>Loading...</p> : <WrappedComponent {...props} />;
};
};
const DataComponent = () => <p>Data Loaded!</p>;
const WrappedDataComponent = withLoading(DataComponent);
What does the withLoading HOC do to the DataComponent?
It creates a HOC that delays rendering until data is loaded
It demonstrates how to handle loading states using a Hook.
It creates a HOC that renders "Data Loaded!" immediately.
It illustrates how to use a HOC to fetch remote data.
To get all Infosys Certified React Expert Exam questions Join Telegram Group https://rebrand.ly/lex-telegram-236dee