코드 1

import React, { useState } from "react";

function Test() {
    const [condition, setCondition] = useState({
        type: "",
        value: "",
    });

    const changeCondition = (key, value) => {
        setCondition((current) => {
            let newCondition = { ...current };
            newCondition[key] = value;
            return newCondition;
        });
    };
    
    return (
        ...
    )
}
 

 

코드 2

import React, { useState } from "react";

function Test() {
    const [condition, setCondition] = useState({
        type: "",
        value: "",
    });

    const {type, value} = condition;
    const onChange = e => {
      const {key, value} = e.target;
      setCondition({
        ...condition,
        [key]: value
      });
    }
    
    return (
        ...
    )
}
 

 

 

 

 

참고 사이트

https://aldrn29.tistory.com/14

https://bgeun2.tistory.com/28

 

 

 

+ Recent posts