MCPcopy
hub / github.com/sudheerj/reactjs-interview-questions / renderView

Function renderView

coding-exercise/src/App.js:10–31  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8 const [currentView, setCurrentView] = useState('home');
9
10 const renderView = () => {
11 if (currentView === 'home') {
12 return <HomePage onNavigate={setCurrentView} />;
13 }
14
15 // Parse the view to get exercise ID and type (problem/solution)
16 const [exerciseId, viewType] = currentView.split('-').reduce((acc, part, idx, arr) => {
17 if (idx === arr.length - 1) {
18 return [acc[0], part]; // Last part is the view type
19 }
20 return [acc[0] ? `${acc[0]}-${part}` : part, acc[1]];
21 }, ['', '']);
22
23 const exercise = exercises.find((ex) => ex.id === exerciseId);
24
25 if (!exercise) {
26 return <div>Exercise not found</div>;
27 }
28
29 const Component = viewType === 'solution' ? exercise.Solution : exercise.Problem;
30 return <Component />;
31 };
32
33 return (
34 <div className="App">

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected