40
loading...
This website collects cookies to deliver better user experience
What is React?
What are the differences between functional and class components?
What is the virtual DOM? How does react use the virtual DOM to render what the user sees?
Explain React state and props.
What is prop drilling in React?
import "./styles.css";
import Row from "./row";
import React, { useState } from "react";
// Build a React Component that displays the given data
// with the functionality of sorting that data and adding rows.
const DATA = [
{ id: 0, name: "John", email: "[email protected]" },
{ id: 1, name: "Jane", email: "[email protected]" },
{ id: 2, name: "Joe", email: "[email protected]" }
];
export default function App() {
const [name, SetName] = useState("");
const [users, SetUsers] = useState(DATA);
const handleChange = (event) => {
SetName(event.target.value);
};
const handleSubmit = (event) => {
const newUser = {
id: users.length,
name: name,
email: `${name}@gmail.com`
};
SetUsers([...users, newUser]);
};
return (
<div className="App">
{users.map((user) => (
<Row key={user.id} name={user.name} email={user.email} />
))}
<input type="text" value={name} onChange={handleChange} />
<button onClick={handleSubmit}> Push Here! </button>
</div>
);
}
import React from "react";
function Row(props) {
return (
<h1>
{props.name}, {props.email}
</h1>
);
}
export default Row;