0
0
Reactframework~20 mins

Component naming rules in React - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
React Component Naming Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2:00remaining
Valid React component names

Which of the following component names is valid in React?

AMyComponent
BmyComponent
C123Component
D_myComponent
Attempts:
2 left
💡 Hint

React components must start with a capital letter and follow JavaScript identifier rules.

component_behavior
intermediate
2:00remaining
Component usage with lowercase vs uppercase names

What will React render when using a component named mybutton in JSX?

Consider these two components:

function mybutton() { return <button>Click</button>; }
function MyButton() { return <button>Click</button>; }

And usage:

<mybutton />
ARenders the custom component output (button with text 'Click')
BThrows a syntax error because component names must be uppercase
CRenders an HTML element named 'mybutton' (unknown tag) instead of the component
DRenders nothing because lowercase components are ignored
Attempts:
2 left
💡 Hint

React treats lowercase tags as HTML elements, not components.

🔧 Debug
advanced
2:00remaining
Why does this component fail to render?

Given this React component code, why does it fail to render anything?

function 2ndComponent() {
  return <div>Hello</div>;
}
AThe component returns invalid JSX syntax
BComponent names cannot start with a digit, causing a syntax error
CReact components must be arrow functions, not function declarations
DThe component is missing a return statement
Attempts:
2 left
💡 Hint

Check JavaScript rules for function names.

🧠 Conceptual
advanced
2:00remaining
Why use PascalCase for React components?

Why is it recommended to name React components using PascalCase (e.g., MyComponent)?

ABecause React treats PascalCase names as components and lowercase as HTML tags
BBecause JavaScript only allows PascalCase function names
CBecause PascalCase components load faster in the browser
DBecause CSS styles only apply to PascalCase components
Attempts:
2 left
💡 Hint

Think about how React distinguishes components from HTML elements.

state_output
expert
2:00remaining
Component name and state hook behavior

Consider this React component:

function mycounter() {
  const [count, setCount] = React.useState(0);
  return <button onClick={() => setCount(count + 1)}>Count: {count}</button>;
}

What will happen when you use <mycounter /> in your app?

AReact throws an error because hooks cannot be used in lowercase named components
BThe button renders and increments count on click as expected
CThe button renders but clicking does not update the count state
DReact treats <mycounter /> as an HTML element and ignores the hook, so no state updates
Attempts:
2 left
💡 Hint

Recall how React treats lowercase JSX tags and hooks usage.