React Cheatsheet Sintaxis Flashcards

Comprehensive React cheatsheet for beginners.

1
Q

JSX Element

A

let element =

<h1>Hello, world!</h1>

;
let emptyHeading = <h1 />;

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

JSX Expressions

A

let name = ‘Josh Perez’;
let element = <h1> Hello, {name} </h1>;

function fullName (firstName, lastName) {
return firstName + ‘ ‘ +
lastName;
}
let element = <h1>Hello, {fullName(‘Julie’, ‘Johnson’)}</h1>

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

JSX attributes

A

const element =
<img src={user.avatarUrl} />;
const element =
<button>
Click me
</button>;

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

JSX Functions

A

name() {
return “Julie”;
}

return (

<h1>
Hi {name()}!
</h1>

)

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

Embed an external component

A

import React from ‘react’;
import ComponentName from ‘component-name’;

export default function UserProfile() {
return (
<div
className="UserProfile">
<ComponentName></ComponentName>
</div>
);
}

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

React Element Styles inline

A

<h1 style={{ fontSize: 24, margin: ‘0 auto’, textAlign: ‘center’ }}>
My header
</h1>

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

React Props

A

function App() {
return <User></User>
}
function User(props) {
return <h1>Hello, {props.name}</h1>; // Hello, John Doe!
}

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

React Props, extract the value of the “name”

A

function App() {
return <User></User>
}
function User({ name }) {
return <h1>Hello, {name}!</h1>; // Hello, John Doe!
}

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

React Children Props

A

function App() {
return (

<User>
<h1>Hello, John Doe!</h1>
</User>

);
}
function User({ children }) {
return children; // Hello, John Doe!
}

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

React IF Conditional

A

function App() {
const isAuthUser = useAuth();
if (isAuthUser) {
// if our user is authenticated, let them use the app
return <AuthApp></AuthApp>;
}
// if user is not authenticated, show a different screen
return <UnAuthApp></UnAuthApp>;
}

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

React ternary operator conditional

A

function App() {
const isAuthUser = useAuth();
return (
<>
<h1>My App</h1>
{isAuthUser ? <AuthApp></AuthApp> : <UnAuthApp></UnAuthApp>}
</>
)
}

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