constructor()

in src/ComponentBase.ts [30:71]


    constructor(props: P) {
        super(props);

        const derivedClassRender = this.render || noop;
        let render = derivedClassRender;
        if (!Options.preventTryCatchInRender) {
            render = () => {
                // Handle exceptions because otherwise React would break and the app would become unusable until refresh.
                // Note: React error boundaries will make this redundant.
                try {
                    return derivedClassRender.call(this);
                } catch (e) {
                    // Annoy devs so this gets fixed.
                    if (Options.development) {
                        // tslint:disable-next-line
                        throw e;
                    }

                    // Try to move on.
                    return null;
                }
            };
        }
        // No one should use Store getters in render: do that in _buildState instead.
        this.render = forbidAutoSubscribeWrapper(render, this);

        const instance = this;
        /*
         * We can't call _buildInitialState here, because the properties of the subclass are initialized **after** the base class
         * constructor. https://github.com/microsoft/TypeScript/issues/1617#issuecomment-69215655
         * Therefore we need to call it after the constructor.
         * Since getDerivedStateFromProps is called after the constructor, we can ensure, that the state is properly initialized
         * there.
         * But we need to put the instance into the state, so that getDerivedStateFromProps works.
         * Hence the rather hacky type conversion.
         */
        // eslint-disable-next-line
        this.state = {
            _resubGetInstance: () => instance,
            _resubDirty: false,
        } as InternalState as unknown as S;
    }