Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useResource #106

Closed
thysultan opened this issue Feb 19, 2019 · 1 comment
Closed

useResource #106

thysultan opened this issue Feb 19, 2019 · 1 comment

Comments

@thysultan
Copy link

thysultan commented Feb 19, 2019

Assuming createResource is implemented to work akin to createContext, we could have a useResource API like useState to register a resource dependency. The resource will return a tuple – the data and a dispatcher to update the data.

Taking facebook/react#14248 as an example, the following model might look something like:

const TodoResource = createResource(data => fetch(`/details`))

function LeftPanel (props) {
  const [state, dispatch] = useState(props)
  const [resource, fetch] = useResource(TodoResource)

  return <button onClick={e => fetch(state)}>Click Me</h1>
}

function RightPanel (props) {
  const [resource, fetch] = useResource(TodoResource)

  return <h1>{JSON.stringify(resource)}</h1>
}

function App () {
  return (
    <Suspense fallback="Loading...">
      <LeftPanel/>
      <RightPanel/>
    </Suspense>
  )
}
@gaearon
Copy link
Member

gaearon commented Aug 24, 2021

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.

@gaearon gaearon closed this as completed Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants