웹개발/react2 react 에서 export 하기 변수/class , import /require 마지막 부분에 변수를 export 할 수도 있고 class나 const hook을 export 할 수도 있다. 이때 1. 변수 export const hello = 'hello'; - 많이 쓸 수 있다 여러 변수를 내보낼 수 있다. - import 시 import {hello} 다음과 같이 {} 로 묶어서 불러온다. 2. class, 함수 등 export default ClassNameHello; - 하나만 내보낼 수 있다. - import 시 import ClassNameHello 로 불러온다. import 와 require 1. import 시 import React, {Component} from 'react'; 2. require const React = require('react'); const.. 2020. 11. 11. React hooks의 setstate 함수가 아닌 hooks를 만들어서 사용할 때 원래 class에서 사용했던 setState를 사용하고 싶을 수 있다. setState가 호출되면 class 의 render()가 다시 실행되는 효과가 있다. 이걸 hook에서 사용하고자 하면 const Hooks = () => { const [first, setFirst] = React.useState(Math.ceil(Math.random() * 9)); const onSubmitForm = (e) => { e.preventDefault(); setFirst(Math.ceil(Math.random() * 9)); }; return ( {first} 입력 ); } 이렇게 작성될 수 있다 setState대신에 setFirst를 호출함으로써 Hooks 전체를 새.. 2020. 11. 11. 이전 1 다음