Skip to main content

is

A utility function that Zedux uses internally to identify class instances.

Zedux uses this instead of instanceof. Zedux can't use JavaScript's instanceof because Zedux is designed to work across windows, with other instances of itself. instanceof can't recognize classes that are instances of a different class reference, even if they're the same "class" in Zedux's eyes.

is() works by checking if a value's .$$typeof property matches a static property with the same name on the given class. These $$typeof properties are JavaScript Symbols, which are properly shared across windows.

Example

import { createStore, is, Store } from '@zedux/react'

const store = createStore()
is(store, Store) // true

class MyCustomStore extends Store {}

const customStore = new MyCustomStore()
is(customStore, Store) // true

Accepted Classes

Here's the full list of Zedux classes that can be checked with is():

Any class that extends these classes works too.

Definition

is = (value, classToCheck) => boolean
value

The value that may or may not be an instance of classToCheck. Can be anything.

classToCheck

A class that contains a public static $$typeof symbol.

Returns

True if value is an instance of classToCheck.