Post Number
# Why do people use react?
React is a cross-platform, which is written on react native component. It can be operated in both android and ios.
React.js - Facebook, Instagram, Twitter, Netflix, etc.
React.native - Faceboook, Instagram, Airbnb, Uber Eats, etc.
React + electron - Slack, etc.
: Componentize all the functions and UIs to enable re-using it.
*Class Form
: It is the most common way to use and the form itself can be saved permanently. (Savings fixed) The variables themselvse are components. Most of developers used class form components since functional form was unable to save the variables permanently.
*Functional Form
: The variables cannot be re-used and can change. But due to hooks, it became possible for functional forms to be a component. Functional components are much more simple and it doesn't require long codes than class components. Here, the variables of the component are called states.
Ex) const [state, setState] = useState()
--> const is different from the const we used in javascript. This const is considered as a kind of forumal. The parameters take initial values. state can't be changed directly by itself so it is changed through setState.
import {useState} from 'react'
export default function LetCount(){
const[count, setCount]= useState(0)
function zzz(){
setCount(count + 1)
}
return(
<div>
<div>{count}</div>
<button onClick={zzz}>Count Up</button>
</div>
)
}
--> Line 1: This decalres that the user is using useState that is provided from react.
--> setCount is having a function for count: The value of count changes through setCount.
--> Here, the initial value of useState is 0. SetCount is the function to change the value of count.
--> The function goes much simple and perhaps the change inside the function is clear and easy.
import {useState} from 'react'
export default function StateSignup(){
const[email, setEmail] = useState("")
const[password, setPassword] = useState("")
const [ mailError, setEmailError = useState("์๋ฌ๋ฉ์์ง๊ฐ ์์ต๋๋ค")
function aaa(event){
console.log(event.target.value)
setEmail(event.target.value)
}
function bbb(event){
setPassword(event.target.value)
}
function ccc(){
console.log("email: " + email)
console.log("password: " + password)
//checking whether the function is correctly responding.
if (email.includes("@") ===false){
setEmailError("์ด๋ฉ์ผ์ @๊ฐ ์์ต๋๋ค. ์๋ชป๋ ์ด๋ฉ์ผ์ด๋ค์") }
else {
alert("ํ์๊ฐ์
์ ์ถํํฉ๋๋ค")
}
}
return (
<div>
์ด๋ฉ์ผ: <input type="text" onChange={aaa}/> <br/>
<span>{emailError}</span> <br/><br/>
๋น๋ฐ๋ฒํธ: <input type="password" onChange={bbb}/> <br/>
{/* <span>{mypwError}</span> <br/><br/> */}
<button onClick={ccc}>ํ์๊ฐ์
</button>
</div>
)
}
-->Initial value is emtpry string for states of email and password.
-->event: event-handler inserts the information of functions that start with -->on to event.
ex) aaa(event) => value from email input goes to the function aaa().
-->setEmail(event.target.value): saving the information of the target to email's state.
-->event.target brings whole < input type="text"/> tag.
-->console.log(event.target.value) -> Gets the value of the target's tag.
-->onChange(contains onInput function; They are used similarly) != onchange(html)
--> Variables that start with use are called hooks, and hooks help function to form components and save variable permanently.
Array Command Functions:
.push => add data at the end of array
.unshift => add data at the first place in array
.pop => deleting the last data in array
.shift => deleting the first data in array
.indexOf() => getting index number of specific data.
let array = ["red","yellow","green"]
array,indexOf(4)
outcome=> -1
.includes() => figuring out the presence of specific data. (Boolean type)
array.includes("yellow")
outcome=> True