Best React Hacks For Lazy Devs

Profile iamgeDan Fleser

Updated: February 11, 20221 min read

Best React Hacks For Lazy Devs

1. Adding console logs to render expressions

If you wanna log the props to an expression style component but can’t be bothered to convert it, put the log in parentheses then add chopsticks ||:

Adding console logs to render expressions

Note. you have to use the or operator because console.log returns undefined.

2. Trace a function’s call with the Error object

If you’ve no idea where a function’s being called from, log an Error object in it and you’ll get a stack trace in the console:

Trace a function’s call with the Error object

3. Ternary question marks

Want to write more ternary question marks? Most people know that using || and && is a super quick way of writing conditions, but did you know there’s a ?? as well?

Ternary question marks

This says, if state?.bookings is undefined return {}.

Hi,
👋
I'm

Dan Fleser

Profile iamge

Full-time web developer since 2014. I recently switched from an 8-5 job to freelancing, which is going great.