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

Integrate react-blockstack package #4

Open
njordhov opened this issue Oct 6, 2019 · 4 comments
Open

Integrate react-blockstack package #4

njordhov opened this issue Oct 6, 2019 · 4 comments

Comments

@njordhov
Copy link

njordhov commented Oct 6, 2019

I am very excited about your gitix project. It's one of the most promising Blockstack projects by far.

I hope you're open to pull requests? I've submitted PR #3, which takes a first stab at integrating the react-blockstack package, providing react hooks for the Blockstack SDK.

@friedger
Copy link
Member

I have merge the PR, but now I am stuck with the question how to add radiks. See njordhov/react-blockstack#3
@njordhov If you want to help fix it, the work to save a relationship between two gitix users (followship) was started in feature/radiks

@njordhov
Copy link
Author

njordhov commented Oct 19, 2019

Radiks should be initialized when the user has been authenticated, right? You can initialize Radiks when userData is determined to be available. In App.js there is a watch/effect triggered by changes to userData, so you may initialize Radiks there just like in the callback to handlePendingSignIn:

useEffect(() => {
      if (userData) {
       /* Initialize Radiks here */
        setSignIn({ checking: false, user: userData, isSignedIn: true });
      } else {
        setSignIn(NotSignedIn);
      }
  }, [userData]);

You can alternatively create a separate watch/effect for Radiks initialization like the one above.

@friedger
Copy link
Member

@njordhov I have added radiks, it looks like it works.

Do you have any ideas how to use react-blockstack in Nav.js?

@njordhov
Copy link
Author

I take you'd like to avoid passing the UserStateContext from Nav.js. Here are some suggestions.

A) As Nav is a react class component, useBlockstack() can't be called from the render function. You may rewrite it to be a function component. Alternatively, factor out the relevant parts from render into function components, specifically those conditioned on signIn.isSignedIn.

B) Note that userData from useBlockstack only is truthy when authenticated, so you can use that to test for isSignedIn. As userData is available in App-Container where the Nav component is used, consider adding an isSignedIn prop to Nav that is set to !!userData, and you should be able to eliminate UserStateContext from Nav by using the isSignedIn prop in place of signIn.isSignedIn from the context.

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