3 ms·
Some functions accept a callback and behave differently depending on whether or not the callback returns a value. If your callback is a single expression arrow
by throwitaway1123 2y ago
Some functions accept a callback and behave differently depending on whether or not the callback returns a value. If your callback is a single expression arrow function, then you might find it cleaner to just void the result instead of wrapping the body of the function in a code block (which prettier will format using multiple lines). Super contrived example:
import { produce } from 'immer'
let i = 1
const a = produce({ x: 0 }, draftState => i++)
const b = produce({ x: 0 }, draftState => void i++)
const c = produce({ x: 0 }, draftState => {
i++
})
console.log({ a, b, c }) // Logs: { a: 1, b: { x: 0 }, c: { x: 0 } }
The immer docs have a section about this pattern: https://immerjs.github.io/immer/return#inline-shortcuts-using-void https://immerjs.github.io/immer/return#inline-shortcuts-usin...