MCPcopy Create free account
hub / github.com/coolvasanth/reactjs_interview_preparation / ErrorBoundary

Function ErrorBoundary

src/Capgemini/Question3.js:12–27  ·  view source on GitHub ↗
({ children })

Source from the content-addressed store, hash-verified

10import React, { useState, useEffect } from 'react';
11
12function ErrorBoundary({ children }) {
13 const [error, setError] = useState(null);
14 const handleError = () => {
15 setError('Something went wrong!');
16 };
17
18 return (
19 <>
20 {error ? (
21 <div>Error: {error}</div> // Fallback UI
22 ) : (
23 children
24 )}
25 </>
26 );
27}
28
29function ChildComponent() {
30 useEffect(() => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected