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

useRPC & useSafeSubmit #21980

Merged
merged 11 commits into from Jan 13, 2020
Merged

useRPC & useSafeSubmit #21980

merged 11 commits into from Jan 13, 2020

Conversation

@chrisnojima
Copy link
Contributor

chrisnojima commented Jan 10, 2020

Adds two new hooks

useRPC

Used when you want a simple rpc that you fire and don't need to participate in redux. This is meant for simple isolated cases where you want to avoid plumbing through a bunch of data for a single component. This assumes no side effects
Usage:

const submit = Container.useRPC(RPCTypes.somethingRpcPromise)
return <div onClick={() => submit(
  [{foo: 'bar'}],
  result => console.log(result),
 error => console.log(error)
)} />

useSafeSubmit

A replacement for the SafeSubmit HOC. Disallows calls after unmount, can stop multiple calls to a callback (per mount)
Usage:

const submitWhileMounted = Container.useSafeSubmit(props.submit)
const submitOnce = Container.useSafeSubmit(props.submit, {onlyOnce: true})
const resetSubmit = React.useRef()
const submitOnceWReset = Container.useSafeSubmit(props.submit, {onlyOnce: reset => resetSubmit.current = reset})

To test the hooks I changed:

  • chat attachments modal to get next/previous attachments using useRPC
  • device add device modal uses useSafeSubmit
chrisnojima added 10 commits Jan 9, 2020
WIP
WIP
WIP
WIP
WIP
WIP
WIP
WIP
WIP
WIP
@chrisnojima chrisnojima requested review from buoyad, mmaxim and keybase/react-hackers Jan 10, 2020
@chrisnojima chrisnojima marked this pull request as ready for review Jan 10, 2020
Copy link

Huynhanh883 left a comment

Duplicate of #

WIP
@mmaxim
mmaxim approved these changes Jan 13, 2020
@mmaxim mmaxim merged commit 71acae3 into master Jan 13, 2020
2 checks passed
2 checks passed
ci/circleci Your tests passed on CircleCI!
Details
continuous-integration/jenkins/pr-head This commit looks good
Details
@mmaxim mmaxim deleted the nojima/HOTPOT-use-rpc branch Jan 13, 2020
thebearjew added a commit that referenced this pull request Jan 13, 2020
thebearjew added a commit that referenced this pull request Jan 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.