hanki.dev

React component props shorthand

With an object you can use shorthand property names, like this:

// Old, boring way
const user = {
   name: name,
   email: email,
   age: age
};

// New, cool way
const user = { name, email, age };

You can't do this with React components (unless it's boolean). But there's something similar which I recently found out about 🤩:

// Old, boring way
<MyComponent
   state={state}
   dispatch={dispatch}
/>

// New, cool way
<MyComponent
   {...{ state, dispatch }}
/>

#react

- 4 toasts