6 ms·
you can do this rather easily by returning an object rather than a primitive. if you're using a language like TypeScript, destructuring the resulting returned o
by disillusionist 1y ago
you can do this rather easily by returning an object rather than a primitive. if you're using a language like TypeScript, destructuring the resulting returned object is rather trivial and (in my opinion) delightful to read.
eg
function combineNames({ first, last }) {
const fullName = `${first} ${last}`;
return { fullName };
}
const { fullName } = combineNames({first: 'John', last: 'Doe' });
- vbezhenar 1y agoFor some reason React prefers to return arrays. I never understood the reason. const [state, setState] = useState(initialState) instead of const {state, setState} = useState(initialState)