[esercizio] React Hooks 2

ytwicey·2020년 12월 18일
0

esercizio

목록 보기
2/7
post-thumbnail

React Hooks 연습하기

2. useInput


import React, { useState } from "react";

const useInput = (initalValue) => {

  const [value, setValue] = useState(initalValue)
  
  const onChange = (e) => { 
    const { target : { value }
        } = e;
    setValue(value)
  }
  return { value, onChange }
}



const App = () => {
 const name = useInput("Mrs.")
 const email = useInput("@")

  return (
    <div className="App">
      <h1>hello</h1>
    <input placeholder = "Name" {...name} />
    <input placeholder = "Email" {...email} />

    </div>
  );
};


export default App;

2. 결과물

profile
always 2B#

0개의 댓글