Skip to content

Instantly share code, notes, and snippets.

@jyydev
Last active July 16, 2021 02:07
Show Gist options
  • Save jyydev/d707f343f9e2e7901ce55fa76552f609 to your computer and use it in GitHub Desktop.
Save jyydev/d707f343f9e2e7901ce55fa76552f609 to your computer and use it in GitHub Desktop.
React > jsx > object > .map()

How to iterate, loop through object in React, reactjs, jsx

const obj = { a: 'aa', b: 'bb' };

return {
  <div>
    {Object.entries(costss).map(([key, cost]) => {
      return (
        <button
          key={cost}
          type='button'
          className='btn'
          onClick={() => setInput(cost)}
        >
          {key}: {cost}
        </button>
      );
    })}
  </div>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment