What’s new in React 16.3(.0-alpha) – Bartosz Szczeciński – Medium

What’s new in #React 16.3(.0-alpha) | @btmpl @Medium  #JavaScript #ReactJS

  • The new API is accessible as React.createContext() and creates two components for us: – Creation of the new context via React.createContextCalling the factory function will return us an object that has a “Provider” and a “Consumer” in it.
  • The “Provider” is a special component which aims to provide data to all components in its sub-tree, so one example of usage would be: – Usage of the new context API — Context.ProviderHere we select a sub-tree (in this case, the whole tree) to which we want to pass our “theme” context,…
  • Next step is to use the Consumer: – Usage of the new context API — Context.ConsumerIf you happen to render the “Consumer” without embeding it in a corresponding “Provider”, the default value declared at createContext call will be used.
  • Please notice some things: – the consumer must have access to the same Context component — if you were to create a new context, with the same parameter as input, a new Context would be created and the data would not be passed.
  • For this reason please consider Context a component — it should be created once and then exported + imported whenever neededthe new syntax uses the function as child (sometime called render prop) pattern — if you’re not familiar with this pattern I recommend reading some articles on itit is no longer required to use…

React 16.3-alpha just hit npmjs and can be downloaded and added to your project. What are the biggest, most interesting changes? Context API was always a thing of mystery — it’s an official…
Continue reading “What’s new in React 16.3(.0-alpha) – Bartosz Szczeciński – Medium”

React Tutorial: A Comprehensive Guide to learning React.js in 2018

  • These components are defined either in pure JavaScript or they can be defined in what the React team calls “JSX”.
  • The reason the React team went with this approach is because, since the virtual DOM is a JavaScript representation of the actual DOM, React can keep track of the difference between the current virtual DOM(computed after some data changes), with the previous virtual DOM (computed befores some data changes).
  • In more layman’s terms, because manipulating the actual DOM is slow, React is able to minimize manipulations to the actual DOM by keeping track of a virtual DOM and only updating the real DOM when necessary and with only the necessary changes.
  • The process looks something like this, – – Some user event which changes the state of your app → Re-render virtual DOM -> Diff previous virtual DOM with new virtual DOM -> Only update real DOM with necessary changes.
  • Signal to notify our app some data has changed→ Re-render virtual DOM -> Diff previous virtual DOM with new virtual DOM -> Only update real DOM with necessary changes.

Continue reading “React Tutorial: A Comprehensive Guide to learning React.js in 2018”

A Comprehensive Guide to React.js in 2018

  • These components are defined either in pure JavaScript or they can be defined in what the React team calls “JSX”.
  • The reason the React team went with this approach is because, since the virtual DOM is a JavaScript representation of the actual DOM, React can keep track of the difference between the current virtual DOM(computed after some data changes), with the previous virtual DOM (computed befores some data changes).
  • In more layman’s terms, because manipulating the actual DOM is slow, React is able to minimize manipulations to the actual DOM by keeping track of a virtual DOM and only updating the real DOM when necessary and with only the necessary changes.
  • The process looks something like this, – – Some user event which changes the state of your app → Re-render virtual DOM -> Diff previous virtual DOM with new virtual DOM -> Only update real DOM with necessary changes.
  • Signal to notify our app some data has changed→ Re-render virtual DOM -> Diff previous virtual DOM with new virtual DOM -> Only update real DOM with necessary changes.

This is the original guide for learning to build apps with React.js. Recently upgraded to support React 16.3 and friends.
Continue reading “A Comprehensive Guide to React.js in 2018”

React Tutorial: A Comprehensive Guide to learning React.js in 2018

  • These components are defined either in pure JavaScript or they can be defined in what the React team calls “JSX”.
  • The reason the React team went with this approach is because, since the virtual DOM is a JavaScript representation of the actual DOM, React can keep track of the difference between the current virtual DOM(computed after some data changes), with the previous virtual DOM (computed befores some data changes).
  • In more layman’s terms, because manipulating the actual DOM is slow, React is able to minimize manipulations to the actual DOM by keeping track of a virtual DOM and only updating the real DOM when necessary and with only the necessary changes.
  • The process looks something like this, – – Some user event which changes the state of your app → Re-render virtual DOM -> Diff previous virtual DOM with new virtual DOM -> Only update real DOM with necessary changes.
  • Signal to notify our app some data has changed→ Re-render virtual DOM -> Diff previous virtual DOM with new virtual DOM -> Only update real DOM with necessary changes.

Continue reading “React Tutorial: A Comprehensive Guide to learning React.js in 2018”

Using Apache Kafka for Asynchronous Communication in Microservices

  • In this post, we’ll look at how to set up an Apache Kafka instance, create a user service to publish data to topics, and build a notification service to consume data from those topics.
  • One of the required configuration options for the Kafka service is , which tells Kafka where to find the Zookeeper instance.
  • To publish data to a Kafka topic, we are going to create a user service that provides two endpoints: – – We use the NPM package to create a producer that connects to Kafka from our node app: – – We create a new promise object that resolves to a…
  • This is used in our function, which publishes data to a Kafka topic partition: – – To consume data from our Kafka topic, we are going to create a notification service that listens for data coming from our topics and sends an email with either a verification code or success…
  • Our two-factor authentication app demonstrates the communication pattern between only two microservices using Apache Kafka (there are other systems like RabbitMQ, ZeroMQ), but by decoupling communication between those services, we add flexibility for the future.

if you’re considering microservices, you have to give serious thought to how the different services will communicate. In this post, we’ll look at how to set up an Apache Kafka instance, create a user service to publish data to topics, and build a notification service to consume data from those topics.
Continue reading “Using Apache Kafka for Asynchronous Communication in Microservices”

Server Rendering with React and React Router

Server Rendering with React and React Router, by @tylermcginnis  #reactjs #react

  • Now that we get the big picture, let’s work on creating the foundation for what will become a server rendered React Router app.
  • Here’s what the React docs have to say about this – – When you’re just rendering a component with no data, it’s not difficult to have the server rendered and client rendered content be identical – as we saw when we just rendered .
  • You need to make sure that the component is rendered with the same data (or props) on both the client and server.
  • The idea is when a GET request is made to our server, instead of calling immediately, we fetch the popular repositories first and then call it after giving our React app the data.
  • The client because it obviously needs to know which components to render as the user navigates around our app and the server because it needs to know which data to fetch when the user requests a specific path.

Continue reading “Server Rendering with React and React Router”

Learning Redux-Saga #javascript #reactjs #redux #redux-saga

Learning Redux-Saga  #javascript #reactjs #redux #redux-saga

  • Redux-saga is a Redux middleware to handle side effects, mainly the asynchronous actions which change the state.
  • A saga is a generator function that can run asynchronous actions indefinitely like a thread in the application.
  • On the other hand, Redux-saga uses the generators which can pause, resume, and interact with the asynchronous actions by using generators.
  • Each of the following functions will return a saga effect which is an object containing instructions of what/how the action should be executed by the saga middleware.
  • takeEvery – – Resolve the effect with the result of each time that the action is received.

Redux-saga is a Redux middleware to handle side effects, mainly the asynchronous actions which change the state. A saga is a generator function that can run asynchronous actions indefinitely like a thread in the application.
Continue reading “Learning Redux-Saga #javascript #reactjs #redux #redux-saga”

What’s new in React 16.3(.0-alpha) – Bartosz Szczeciński – Medium

  • It is definitely more “user friendly” and might make your life a bit easier when all you want is simple state management without the “overhead” of Redux or MobX.The new API is accessible as React.createContext() and creates two components for us:Creation of the new context via React.createContextCalling the factory function…
  • Next step is to use the Consumer:Usage of the new context API — Context.ConsumerIf you happen to render the “Consumer” without embeding it in a corresponding “Provider”, the default value declared at createContext call will be used.Please notice some things:the consumer must have access to the same Context component — if you were to…
  • For this reason please consider Context a component — it should be created once and then exported + imported whenever neededthe new syntax uses the function as child (sometime called render prop) pattern — if you’re not familiar with this pattern I recommend reading some articles on itit is no longer required to use…
  • New life-cycle methodsThe other RFC to make it into the alpha release concerns deprecation of some life-cycle methods and introduction of one (four) new.This change aims to enforce best practices (you can read up on why those functions can be tricky in my article on life-cycle methods) which will be…
  • Instead the function should return the updated state data, or null if no update is needed:Using getDerivedStateFromProps in order to update stateThe returned value behaves similarly to current setState value — you only need to return the part of state that changes, all other values will be preserved.Things to keep in mind:Remember to init state!You…

React 16.3-alpha just hit npmjs and can be downloaded and added to your project. What are the biggest, most interesting changes? Context API was always a thing of mystery — it’s an official…
Continue reading “What’s new in React 16.3(.0-alpha) – Bartosz Szczeciński – Medium”

Learning Redux-Saga #javascript #reactjs #redux #redux-saga

Learning Redux-Saga  #javascript #reactjs #redux #redux-saga

  • Redux-saga is a Redux middleware to handle side effects, mainly the asynchronous actions which change the state.
  • A saga is a generator function that can run asynchronous actions indefinitely like a thread in the application.
  • On the other hand, Redux-saga uses the generators which can pause, resume, and interact with the asynchronous actions by using generators.
  • Each of the following functions will return a saga effect which is an object containing instructions of what/how the action should be executed by the saga middleware.
  • takeEvery – – Resolve the effect with the result of each time that the action is received.

Redux-saga is a Redux middleware to handle side effects, mainly the asynchronous actions which change the state. A saga is a generator function that can run asynchronous actions indefinitely like a thread in the application.
Continue reading “Learning Redux-Saga #javascript #reactjs #redux #redux-saga”

Taking Gatsby for a spin

Taking Gatsby for a spin  #webdev #javascript #reactjs #Flexi_IT

  • It’s not that I really need a new tool to create static sites, it’s just that every developer tweeting about Gatsby seems to think it’s the most exciting thing on the web since they learned they could combine the and tag.
  • Here are some of the important features of Gatsby: – – GatsbyJS is based on React which means that you’ll be writing almost everything in JavaScript / JSX.
  • If you already like React, you’ll most definitely enjoy creating static sites with Gatsby.
  • Gatsby comes with plugins to pull in data from several APIs, CMS systems and local files.
  • PRPL + the gatsby offline plugin mean that your site will be considered a PWA, will load insanely fast on any device and scores great in Google lighthouse.

A short write-up on Gatsby, a static site generator based on React
Continue reading “Taking Gatsby for a spin”