GraphQL Authentication with React Native & Apollo [Part 2/2]

GraphQL authentication with React Native & Apollo  #GraphQL #ReactNative #Apollo

  • We’ll use gql to write our graphql query and the graphql higher order component to tap into the Apollo client.We know that our mutation looks something like this (from working with it directly in Launchpad in part 1).
  • Now we need to to be able to pass variables from our user to the mutation.Finally, we want to make this mutation available to the Register component via this.props so that the component agnostic from the Apollo bindings.Now to use it we’ll go to the end of our handleSubmit function…
  • Click “Log Out”, refresh the app, and you’ll see it no longer brings you to profile.Login with Email and PasswordLogging in with email and password is just like sign up, we’re just calling a different mutation.
  • I’ll let the code do the talking.Now to call the login function available on this.props, save the JWT and change screens (on success) or show an error.Showing User InformationThe final thing we’ll do, to demonstrate that things are actually working and it’s not just a big facade, is show the…
  • The server is expecting the JWT to be coming in the authorization header and uses that to find the current user.To pass this token along with the request we’ll use setContext from the apollo-link-context which is another apollo link we’ll use.

This is the second and final part of a series where I cover how to setup authentication with React Native, GraphQL, and MongoDB. Below is part 1 where we setup the server. In this part we’ll be…
Continue reading “GraphQL Authentication with React Native & Apollo [Part 2/2]”

I am Loving this Jelly Fish Splash React Animation see via @CodePen #ReactJs #React

  • You can apply CSS to your Pen from any stylesheet on the web.
  • Just put a URL to it here and we’ll apply it, in the order you have them, before the CSS in the Pen itself.
  • If the stylesheet you link to has the file extension of a preprocessor, we’ll attempt to process it before applying.
  • You can also link to another Pen here, and we’ll pull the CSS from that Pen and include it.
  • If it’s using a matching preprocessor, we’ll combine the code before preprocessing, so you can use the linked Pen as a true dependency.

Recreated https://dribbble.com/shots/2896850-Animated-DropSplash-Logo-Posibility with React and SVG…
Continue reading “I am Loving this Jelly Fish Splash React Animation see via @CodePen #ReactJs #React”

ReactJs: Using stores to improve your code – Doyin Olarewaju – Medium

ReactJs: Using stores to improve your code  #reactjs #react #javascript #reactjs

  • ImagesOne of the first steps i take is to create an ImageStore.
  • This helps me keep all images in one place, helps ensure my images are compiled with react and also helps me not worry about relative links to my app root.So some code://say the name of this file is ImageStore located at stores/ImageStoreimport UserImage from FriendImage from default { UserImage, FriendImage}Then to import it in your viewsimport ImageStore from ‘.
  • /stores/ImageStore// excluded some imports for brevity sake………export default class TestClass extends Component {render() img src={ImageStore.UserImage} alt=’User’ / … … }}Thats it.
  • Just add all images you wish to use in your app into the store and import the ImageStore.
  • No relative links required, the image gets compiled into your app and best of all, if the image location needs to change for any reason all you need to do is change in the ImageStore file and it changes everywhere.

I’m a sucker for well written code. When code is badly written, the app kinda gets boring and it becomes a task to work on the codebase. I love stores in js, especially since es6. Simple classes with…
Continue reading “ReactJs: Using stores to improve your code – Doyin Olarewaju – Medium”

Testing with Mocha – Kevin Wang – Medium

Testing with Mocha  #tdd #react #mocha #javascript #reactjs

  • js file and running “npm test” in the console.var assert = function() { describe(‘#indexOf()’, function() { it(‘should return -1 when the value is not present’, function() { assert.equal(-1, [1,2,3].
  • indexOf(4)); }); });});The test should pass and you should see the below.From the example above though, the function that the test is testing for is written in the same file.
  • toFixed(2) }, sleepApneaIncrease: function(amount){ return (amount * 1.06).
  • toFixed(2) }, heartDiseaseIncrease: function(amount){ return (amount * 1.17).
  • toFixed(2) }, checkCondition: function(amount, condition){ switch (condition) { case “Allergies”: return case “Sleep Apnea”: return case “Heart Disease”: return default: return 0; } }}I store them all in an object so thatI am able to export out and require them when I need to.

My first experience with Mocha is at Flatiron. When we were doing Javascript labs/work we used Mocha to test out the code that we wrote, it made sure that the results are as we expected. This was my…
Continue reading “Testing with Mocha – Kevin Wang – Medium”

Migrating to react-router v4…the SSR way – Frontend Weekly – Medium

Check out our new article: Migrating to react-router v4…the SSR way  #ReactJS

  • Now you need 2 types of router :BrowserRouter on the Client side and StaticRouter on the stateless server side.v3const ReactRouterContext = ReduxProvider = routes, location: req.url }, (err, redirectLocation, renderProps) = { if (err) { res.status(503); } else if (redirectLocation) { return res.redirect(302, redirectLocation.pathname + redirectLocation.search); } else if (renderProps) { return res.send(`!
  • DOCTYPE ReduxProvider({ store }, } return null; });but in v4, match no longer exists, as StaticRouter handles it all on the server side.
  • All we need to do is to render the same Router configurations in the server as in Client to match the checksum and that’s it.
  • if (context.url) { return res.redirect(302, context.url); } else { const renderHTML = ReactDOMServer.renderToString( ReduxProvider( { store }, serverConfig(req, context) ) ); return res.send(`!
  • This only needs to be rendered on the server side.const serverConfig = (req, context) = ( StaticRouter location={req.url} context={context} App / /StaticRouter);In order to match the checksum, a client-side version router is needed of course.const history = Provider store={initStore} Router history={history} App / /Router /Provider, Up Server and ClientServer: ReduxProvider(essentially createFactory – props store in)Client: Provider

Migrating to React v15.5 is a good preparation for the full embrace of React v16 (:scream), and it wasn’t too much of a pain as it was mostly with React.PropTypes deprecation and some other API…
Continue reading “Migrating to react-router v4…the SSR way – Frontend Weekly – Medium”

React-motion 101: Springs – Bjorn Holdt – Medium

React-motion 101: Springs  #reactjs #reactmotion #javascript #react #animation #reactjs

  • Box 2 is different.
  • Instead the law of physics, in particular a spring, was used to create the animation.
  • You can tell a spring was used because towards the end of the animation, it takes a while for the box to settle into its final position.
  • Box 1, 3 and 4 animation will look a bit jarring if we interrupt it.
  • Box 2 on the other hand handles the change gracefully and naturally springs into its new position (play around with these values on codepen)Stiffness and damping to change animationIn a spring animation, there are two variables you can control: stiffness and damping.

Boxes 1, 3 and 4 all used different timing functions (ease-in, ease-out, linear). However, they were all timed animations set to run for 500ms. Box 2 is different. The animation wasn’t set to run for…
Continue reading “React-motion 101: Springs – Bjorn Holdt – Medium”

React Lifecycle, Quickly by the Method – Gabriel Kunkel – Medium

React Lifecycle, Quickly by the Method  #javascript #react #reactjs

  • React Lifecycle, Quickly by the MethodThese methods aren’t perfectly desirable to use, but they’re a way of exerting more control over the situation when the rest of the world just doesn’t want to cooperate with React.componentWillMount: Use for connecting to API’s on root components or containers.
  • componentDidMount: Load your data and do anything you need to do to a component.
  • After a parent component did some value changing.
  • This is the place to change outside DOM things in respect to changes that are linked up to the values tracked by react.
  • If you’re going to kill your component, this is the place where you clean-up everything that react won’t clean up on its own, including network requests, event listeners, and a canvas box.The whole cycle with methods.

These methods aren’t perfectly desirable to use, but they’re a way of exerting more control over the situation when the rest of the world just doesn’t want to cooperate with React.
Continue reading “React Lifecycle, Quickly by the Method – Gabriel Kunkel – Medium”