When using the useGate
hook in the React SDK, if the provider does not wait for initialization and useGate
is called before the initialization completes, it will return false on the initial read. However, once the client eventually initializes, it will cause a re-render of the component that is using the useGate
hook.
This re-render is triggered because the useGate
hook updates its state with the actual value of the gate once initialization is complete. It's important to note that this re-render will occur regardless of whether the gate value is true or false. The key point is that the state of the gate has updated, which triggers the re-render.
For handling loading states while the Statsig client initializes, you can use the isLoading
value. Once the Statsig client state changes, your component will be called again and you can handle the true/false gate state as desired. For more details, refer to the Statsig React SDK documentation.