reactjs/rfcs

[Proposal] Expose predicate of react's render state to enforce suspense invariants

achung89 opened this issue · 1 comments

I'm creating a library for suspense and I would like to enforce these invariants

const blogsResource = createResource(fetchBlogs) // this is okay

const blogs = blogsResource.read({ author: 'me'}) // this should error

const App = () => {
  const appBlogs = blogsResource.read({ author: 'me'}) // this is okay
  const appBlogsResource =  createResource(fetchBlogs) // this should error
  return <div>foo</div>
}

I have no way to prevent someone from prefetching(and caching) inside render or suspending outside render. Could we have a predicate of react's render state (true/false) that would allow us to maintain these invariants?

Hi, thanks for your suggestion. RFCs should be submitted as pull requests, not issues. I will close this issue but feel free to resubmit in the PR format.