Skip to content

Update docs: loading state is false on first render #69

@andyGallagher

Description

@andyGallagher

Hi — really loving this library, thanks for your excellent work here.

I've noticed a behavior that I would appreciate some clarification on. On initial renders without any conditional logic, loading is set to false and data is undefined.

Subsequently, the doc's example usage, while obviously contrived, does not work in a way I would expect:

// components/Post.tsx
const Post = () => {
  const { data, loading } = useStore($currentPost);

  if (data) return <div>{data.content}</div>;
  if (loading) return <>Loading...</>;

  console.warn("💀 This is actually rendered!  Not what I would expect.");
  return <>Error!</>;
};

You can see live examples of this log here.

This is easy enough to work around, as you can just create a function that tracks an initialization state that looks at if loading has ever been toggled from false to true. That said, I'd like to recommend updating the docs to make note of this behavior. Let me know what you think; happy to open a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions