M
M
miliko mikoyan2019-02-22 09:51:28
React
miliko mikoyan, 2019-02-22 09:51:28

How to pass value from object to div tag?

i have x object ,

const x = {
  d: { D: 10 },
  f: { F: 11 },
  g: { G: 12 }
}

I want to pass all values ​​to div tag, how do i make the shortest option
<div D={10} F={11} G={12} ></div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
davidnum95, 2019-02-22
@miliko0022

const props = Object.values(x).reduce((result, item) => ({...result, ...item}), {});
<div {...props} />

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question