R
Reactiflux

help-js

πŸŽƒ Spookyberb πŸŽƒ – 13-03 Nov 23

Sβ›„Snowberbβ›„11/23/2022
Will this piece of code crash the app if it doesnt find anything?
const { fullName } = clients.find((client) => client.clientId === customerId);
const { fullName } = clients.find((client) => client.clientId === customerId);
UUUnknown User11/23/2022
2 Messages Not Public
Sign In & Join Server To View
SScriptyChris11/23/2022
@β›„Snowberbβ›„ add a default value if .find() returns null:
const { fullName } = clients.find((client) => client.clientId === customerId) ?? { fullName: '' };
const { fullName } = clients.find((client) => client.clientId === customerId) ?? { fullName: '' };
Sβ›„Snowberbβ›„11/23/2022
ooo I like this that's what I wanted but why ?? and not ||?
UUUnknown User11/23/2022
Message Not Public
Sign In & Join Server To View
SScriptyChris11/23/2022
Alternatively you could use optional chaining without spread πŸ€”
const fullName = clients.find((client) => client.clientId === customerId)?.fullName;
const fullName = clients.find((client) => client.clientId === customerId)?.fullName;
!mdn optional chaining
UUUnknown User11/24/2022
2 Messages Not Public
Sign In & Join Server To View

Looking for more? Join the community!