Basics Flashcards

1
Q

What is the app.js file?

A

This is the main component of your React application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the index.js file?

A

This file is the entry point of your React application. It is responsible for rendering the root component (App.js) and attaching it to the HTML document.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Write out the app.js file for basic starter project, returning an empty div.

A
import React from 'react';
import './style.css';

export default function App() {
  return (
    <div>            
    </div>
  );
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Write out index.js file for basic starter project.

A
import React, { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';

import App from './App';

const root = createRoot(document.getElementById('app'));

root.render(
  <StrictMode>
    <App />
  </StrictMode>
);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define a simple functional component that displays the text “Hello”.

A
function Intro() {
  return (
    <div>Hello</div>
  );
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Write out the App component, including a single component inside it name

A

`
export default function App() {
return (
<div><Intro></Intro></div>
);
}
`

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Create two components, MyComponent and ChildComponent. Using props, pass a prop name ‘title’ into ChildComponent, and in the child display it as the value inside h1 tags.

A
function MyComponent(){
  return <MyChildComponent title = 'My Title'/>
}
function MyChildComponent(props){
  return <h1>{props.title}</h1>
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Where is the root div element that is rendered by React?

A

In the index.html file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the index.html file?

A

The main html page inside which react is rendered.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to you render the root element?

i.e. what is the syntax. Assume the main component is <MyComponent></MyComponent>

A
root.render(
        <MyComponent>
  );
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

(two lines)

How to you get the root element?

i.e. what syntax?

A
const rootElement = document.getElementById('root');
const root = createRoot(rootElement);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly