[React] Week1_1
Introduction to React :
Using basic JavaScript syntax:
Acquire ES6 syntax and use map and filter within React components.
Understanding React's characteristics and utilizing components:
Understand the background of React's birth in the modern web and divide it into reusable component units within the screen.
Understanding and utilizing React's Props and State concepts:
Understand why immutability must be maintained and use props and state to pass functions.
Assignment: Create a Todo List.
- What is React?
React is a declarative and efficient JavaScript library for building user interfaces. It is known as "components" and helps to construct complex UIs using small, isolated pieces.
Main features:Component-based: React allows you to break down your UI into reusable and independent pieces called "components" which can be composed to create complex UIs.
- Declarative views
- JSX
- Hooks:
- State & Props:
- Component-based:
React allows you to break down your UI into reusable and independent pieces called "components" which can be composed to create complex UIs.
Official doc :
https://ko.legacy.reactjs.org/docs/faq-internals.html#gatsby-focus-wrapper
Virtual DOM과 Internals – React
A JavaScript library for building user interfaces
ko.legacy.reactjs.org
1-2. Javascript ES6
ES6 (ECMAScript 2015) is the sixth major version of the ECMAScript language specification, which is the standardized specification for JavaScript. It was released in 2015 and introduced many new features and syntax improvements to the language.
Some of the new features introduced in ES6 include:
- Arrow functions
- Template literals
- Destructuring assignment
- Rest and spread operators
- Classes and inheritance
- Promises and async/await
- let and const declarations
- Default function parameters
ES6 also introduced some changes to the way variables are scoped and hoisted in JavaScript, and introduced new methods and syntax for manipulating arrays and objects.
Overall, ES6 greatly improved the functionality and syntax of JavaScript, making it easier and more efficient to write complex code. It has since been followed by newer versions of ECMAScript, including ES7 (2016), ES8 (2017), ES9 (2018), ES10 (2019), ES11 (2020), ES12 (2021), and ES13 (2022), each with its own set of new features and improvements.
1.Arrow Function: A shorter and more concise way of writing a function in JavaScript using the => operator.
// Traditional function
function add(a, b) {
return a + b;
}
// Arrow function equivalent
const add = (a, b) => a + b;
2.Spread operator: A way to spread the elements of an array or object into another array or object.
// Spreading an array
const numbers = [1, 2, 3];
const newNumbers = [...numbers, 4, 5, 6]; // [1, 2, 3, 4, 5, 6]
// Spreading an object
const person = { name: 'John', age: 30 };
const newPerson = { ...person, address: '123 Main St' }; // { name: 'John', age: 30, address: '123 Main St' }
3. Destructuring assignment and rest operator:
In this example, the destructuring assignment syntax [first, second, ...rest] = numbers assigns the first element of the numbers array to the first variable, the second element to the second variable, and the rest of the elements to the rest variable as an array using the rest operator ....
const numbers = [1, 2, 3, 4, 5];
const [first, second, ...rest] = numbers;
console.log(first); // 1
console.log(second); // 2
console.log(rest); // [3, 4, 5]
2. React Setting
Normally, we use yarn:
There are some differences between two : Performance, Dependency resolution , Lockfile format, CLI interface.
Use CRA (Create-react-app) :
yarn create react-app week-1 #create project
and you can start
yarn start
3. Component
It works like lego block.
You build a big project by components.
function App(){
return <div></div>
}
How to make components :
//out side of component , import any other file
import React from "react";
const App =()=>{
// use javascript syntax here
}
return(
<div>
{/* use JSX */}
</div>
);
};
// exporting the component
export default App;
Capitalizing the first letter of a component's name is a convention in many programming.
A class component is a way of creating a React component by using a class that extends the React.Component class. It allows you to control the component's behavior using lifecycle methods and state and props.
A function component, on the other hand, is a simpler way of creating a React component by using a function that returns JSX. It only uses props and can use Hooks to manage state and replace lifecycle methods.
For example, here's a class component that displays a message:
// class compoenent
class Greeting extends React.Component {
render() {
return <h1>Hello, {this.props.name}!</h1>;
}
}
// function compoenent
function Greeting(props) {
return <h1>Hello, {props.name}!</h1>;
}
Child Component :
You can put components inside of another component.
Here are some JSX rules to keep in mind:
- Always close your tags.
- Always return one element.
- Use curly braces to insert JavaScript values.
- Use className instead of class.
We can connect components within component as following :
import React from 'react';
import { toast, ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
function App() {
const notify = () => toast("Wow so easy!");
const notify2 = () => {
alert('hi!');
};
const GrandParent = () => {
return <Parent />
}
const Parent = () => {
return <Child />
}
const Child = () => {
return <div> I am the son fucker </div>
}
return (
<div
style={{
height: '100vh',
display: ' flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
}}
>
<p1> This is App component </p1>
<GrandParent />
</div >
);
}
export default App;
Search More :
1. JavaScript has various methods that can be used with objects and built-in data types.
2. You can create a project not CRA / other way
'IT > Web Programming' 카테고리의 다른 글
CS Study - 면접을위한 CS전공 지식 노트 1 (0) | 2024.02.13 |
---|---|
[Core Javascrpt] 01. Data type (0) | 2023.06.19 |
[ 토크부트] 토크부트(talkbout) 부트캠퍼들의 커뮤니티 (0) | 2021.08.28 |
[ 토크부트] 부트캠퍼들의 속시원한 이야기 토크부트(talkbout) (0) | 2021.08.27 |
[Django] Python Django 파이썬 장고 (0) | 2021.03.08 |