Skip to content

1.2.0

Compare
Choose a tag to compare
@alexreardon alexreardon released this 31 Oct 22:06
· 42 commits to master since this release

New: Get message function

The message provided to invariant can now be a function that returns a string

- export default function invariant(condition: any, message?: string): asserts condition;
+ export default function invariant(condition: any, message?: string | (() => string)): asserts condition;

Using a function that returns a string is helpful in cases where your message is expensive to create. By using a function you only need to create the message when you need it.

import invariant from 'tiny-invariant';

invariant(value, () => getExpensiveMessage());

Keep in mind, that ideally the second argument to invariant is stripped away entirely in production builds.

We have a guide on how to do remove messages for production builds