Skip to content

Comments

Propose Recoil for Global State#1

Open
MorganIsBatman wants to merge 1 commit intomasterfrom
proposal/recoil-for-global-state
Open

Propose Recoil for Global State#1
MorganIsBatman wants to merge 1 commit intomasterfrom
proposal/recoil-for-global-state

Conversation

@MorganIsBatman
Copy link
Collaborator

This is a proposal for adding Recoil (https://recoiljs.org) for global state, with a couple of hooks set up to demonstrate its use, so we have a basis for conversation.

Recoil is created by Facebook (creators of react) to be the goto state-management lib for react. It does away with a lot of redux' boilerplate for an API that at its most basic resembles useState (but with selectors and more advanced usage available).

In this PR:

  • useMetamask: A hook providing functionality so a user can connect their metamask wallet, and access the account, provider and signer anywhere in the app using either the hook, or useRecoilValue
  • useContract: A hook to abstract the common code when connecting to contracts

Set up useMetamask and useContract hooks to demonstrate the convenience provided by recoil
undefined
);

const metamaskState = useRecoilValue(metamaskState)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useRecoilValue is a hook if you only need to READ state, whereas useRecoilState is a simile to useState, giving you [state, setState] equiv

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

Successfully merging this pull request may close these issues.

1 participant