Explore the foundational concepts of React.js, including setup, components, JSX, and state management. Ideal for those beginning their journey into frontend development with React.
Which command is commonly used in the terminal to create a new React app using a widely adopted setup tool?
Explanation: The command 'npx create-react-app my-first-react-app' utilizes Create React App to quickly scaffold a new React project with sensible defaults. 'npm start react-new-app' would attempt to start a project rather than create one. 'react-init project-name' and 'node create app-react' are not valid commands for initializing React projects.
What is a component in React?
Explanation: A React component is a reusable, self-contained code unit that controls how certain parts of the UI appear and behave. A style sheet manages visual styles, a database query function handles backend data, and configuration files are used for deployment settings, not UI rendering.
Which of the following represents valid JSX in a React component?
Explanation: JSX looks similar to HTML but is written within JavaScript code, as shown in the correct option. The second and third options use incorrect syntax, and the fourth uses standard JavaScript without JSX.
How can you define a state variable called 'count' in a functional React component?
Explanation: In functional components, the useState hook creates a state variable and an updater. 'let count = this.state.count;' is used in class components. 'state count = 0;' and 'var count = new State(0);' are not valid React syntax.
If a parent React component wants to pass information to a child component, what mechanism should be used?
Explanation: Props allow a parent component to pass information to its children and are read-only in the child. State is used for local data management within a component, CSS Modules are for styling, and useEffect is a hook for side effects, not data passing.