0

I want to make a lot of variables like the below code. I think if I use the maps function it will work, but it does not work. Could you teach me how to reduce the code?

const name = useInput("");
  const area = useInput("");
  const job = useInput("");
  const company = useInput("");
  const school = useInput("");
  const tall = useInput("");
  const body = useInput("");
  const religion = useInput("");
  const smoking = useInput("");
  const blood = useInput("");
  const birthday = useInput("");
  const kakao = useInput("");
  const image1 = useInput("");
  const image2 = useInput("");
  const image3 = useInput("");
  const introduction = useInput("");
Chris
  • 1,206
  • 2
  • 15
  • 35
박형렬
  • 377
  • 1
  • 9
  • 24

2 Answers2

1

Maybe you can convert it to array and object

const arr = ['name', 'area', etc...];
const obj = {};
arr.forEach(key => {
 obj[key] = useInput(key);
}
0

I hope this works for you

Array(16) please change number according to your variables

const [name,area,job,company,school,tall,body,religion,smoking,blood,birthday,kakao,image1,image2,image3,introduction] = Array(16).fill().map(() => useInput(""))
Jay
  • 2,826
  • 2
  • 13
  • 28