Hooks(2)
-
[React] 나만의 Hook 만들기
💡 브라우저의 가로 창 사이즈가 변경됐을때 변경된 정도를 가져오는 훅을 만들 예정이다. import React from "react"; export default function useWindowWidth() { const [width,setEidth] = React.useState(window.innerWidth); // window.innerWidth : 현재 브라우저의 가로값 return width; } useWindowWidth.js import logo from './logo.svg'; import './App.css'; import useWindowWidth from './hooks/useWindowWidth'; function App() { const width = useWindowWidth..
2023.06.23 -
[React] Hooks 알아보기 ( useState , useEffect )
함수 앞에 use 를 붙여 리액트에서 낚아서 슬 수 있도록 만든걸 react hooks 라고 부른다. 함수형 컴포넌트가 클래스형 컴포넌트같은 기능을 할 수 있게 해준다. useState class 컴포넌트로 state 를 활용해서 만들것이다. import React from 'react'; export default class Example1 extends React.Component { state = {count : 0}; render() { const {count} = this.state; // state 는 객체 return ( You clicked {count} times Click me ); } click = () => { this.setState({count: this.state.count +..
2023.06.23