Karim Aya

Karim Aya

1569984465

Documenting React Components With Storybook

What Is Storybook?

Storybook markets itself as a playground for UI components and its main focus is on “writing stories.”

Storybook uses the concept of stories to document components.

A story usually contains a single state of one component, almost like a visual test case. Technically a story is a function that returns something that can be rendered to a the screen.

Your component storybook will contain many different stories for many different components.

Each story we write will contain a single state, for example:

Button
  ├── primary
  ├── secondary
  └── tertiary

What’s great about Storybook is that it works with many popular front-end frameworks and libraries such as React, Vue, React Native, Angular, and more.

Set Up

For this tutorial, I’ll be adding Storybook to my Building Design Systems With React talk which I gave in May 2019 at ReactJS Girls London. You’re welcome to follow along with your own code, or check out the final code in my repository.

  1. Change into your project directory and install your dependencies (if you need to). I forgot and spent ten minutes trying to figure out why nothing was working…

Then, install the boilerplate files for Storybook. (This will take a hot second to download. In the meantime, perhaps you’d like to brew some fresh coffee.)

cd my-project
npx -p @storybook/cli sb init

This tool will check out your package.json file to determine which framework or library (view layer) you’re using. If automatic detection fails, or if you want to use Storybook for HTML, use the following command:

npx -p @storybook/cli sb init --type html | 

  1. Once installed, let’s start Storybook with the following command:
npm run storybook

After running, a localhost window popped up in my browser and I saw this screen:

Storybook

  1. Now we’ll want to add Storybook as a development dependency within our project. We can do that by running the following command:
npm install @storybook/react --save-dev

  1. Storybook has a few peer dependencies which we also need to have installed. react and react-dom should be saved as normal dependencies. @babel/core and babel-loader should be saved as development dependencies.
npm install react react-dom --save
npm install babel-loader @babel/core --save-dev

  1. We’ll want to add an npm script so we can easily start Storybook. Inside our package.json file, let’s add a storybook script.
{
  "scripts": {
    "storybook": "start-storybook"
  }
}

  1. Lastly, let’s create the Storybook config file, which will simply tell Storybook where we’ll be writing our stories.

You most likely already have this file created from the previous steps, however if you don’t, create a new config.js file inside the storybook/ folder.

My config.js file contains the following:

import { configure } from "@storybook/react";

function loadStories() {
  require("../src/stories");
}

configure(loadStories, module);

This tells Storybook to look inside of the src/stories folder for our stories.

Let’s Document

  1. Ensure your development server is running with npm run storybook.
  2. First, we’ll get rid of the boilerplate inside of src/stories/index.js. My file looks like this:
import React from "react";
import { storiesOf } from "@storybook/react";
import { action } from "@storybook/addon-actions";

  1. Now, let’s import our first component. For my project, I’ll be importing my Button component. It lives directly inside of the src/ folder.
import Button from '../Button';

I’m using enums to describe my button types, so I’ll import those as well.

import { ButtonTypes } from "../buttonTypes";

  1. We now want to write our first storiesOf for our button. We’ll start with three states: primary, secondary, and tertiary.

We need to use the .add() function to add each state. This takes two arguments: the name of the state we want to add and a function which returns the component.

Here is what my index.js file looks like:

import React from "react";

import { storiesOf } from "@storybook/react";
import { action } from "@storybook/addon-actions";

import Button from "../Button";
import { ButtonTypes } from "../buttonTypes";

storiesOf("Button", module)
  .add("primary", () => (
    <Button
      type={ButtonTypes.PRIMARY}
      onClick={action("clicked")}
      label="Primary"
    />
  ))
  .add("secondary", () => (
    <Button
      type={ButtonTypes.SECONDARY}
      onClick={action("clicked")}
      label="Secondary"
    />
  ))
  .add("tertiary", () => (
    <Button
      type={ButtonTypes.TERTIARY}
      onClick={action("clicked")}
      label="Tertiary"
    />
));

When we check this out in the UI, we should see one story, Button, with three states: primary, secondary, and tertiary.

Storybook

  1. Now that this is working, I want to modularize my stories a bit better. If I were doing this for an enterprise application, or a full design system, I’d add the stories next to the components themselves. However, due to the fact that this is a proof-of-concept, I’ll be adding them within the stories/ folder.

I’ll create a buttonStories.js file inside of src/stories/.

Next, I’ll copy and paste all of the code from the index.js file over to this new file.

Lastly, I’ll update index.js to import the buttonStories.js file.

import "./buttonStories";

And that’s it! You now can create Storybook stories to document the states of your component.

Theming

You can select different themes for your Storybook documentation.

Dark Theme

  1. Import addParameters and themes:
import { addParameters } from '@storybook/react';
import { themes } from '@storybook/theming';

  1. Next, add the theme key to the parameter options:
import { addParameters } from '@storybook/react';
import { themes } from '@storybook/theming';

// Option defaults.
addParameters({
  options: {
    theme: themes.dark,
  },
});

And voila, a dark theme!

Dark theme

Custom Themes

You can generate a custom theme by using the create() function.

  1. Create a new file within the .storybook folder, and name it appropriately for your theme. I’ll call mine purpleDream.js

  2. Paste the following code and update the values to suit your theme’s needs.

import { create } from "@storybook/theming";

export default create({
  base: "dark",

  colorPrimary: "mistyrose",
  colorSecondary: "purple",

  // UI
  appBg: "#9f84bd",
  appContentBg: "#ede3e9",
  appBorderColor: "grey",
  appBorderRadius: 4,

  // Typography
  fontBase: '"Open Sans", sans-serif',
  fontCode: "monospace",

  // Text colors
  textColor: "white",
  textInverseColor: "rgba(255,255,255,0.9)",

  // Toolbar default and active colors
  barTextColor: "white",
  barSelectedColor: "white",
  barBg: "#ca7df9",

  // Form colors
  inputBg: "white",
  inputBorder: "silver",
  inputTextColor: "white",
  inputBorderRadius: 4,

  brandTitle: "My custom storybook",
  brandUrl: "https://example.com",
  brandImage: "https://placehold.it/350x150"
});

  1. Update your config.js file to use your new theme.
import { configure } from "@storybook/react";
import { addParameters } from "@storybook/react";
import purpleDream from "./purpleDream";

function loadStories() {
  require("../src/stories");
}

addParameters({
  options: {
    theme: purpleDream
  }
});

configure(loadStories, module);

And there you go. You now have a custom theme (hopefully not as ugly as mine.)

Purple dream


I hope you enjoyed this tutorial on getting started with Storybook & React. Feel free to check out my code on GitHub.

#reactjs

What is GEEK

Buddha Community

Documenting React Components With Storybook
Autumn  Blick

Autumn Blick

1598839687

How native is React Native? | React Native vs Native App Development

If you are undertaking a mobile app development for your start-up or enterprise, you are likely wondering whether to use React Native. As a popular development framework, React Native helps you to develop near-native mobile apps. However, you are probably also wondering how close you can get to a native app by using React Native. How native is React Native?

In the article, we discuss the similarities between native mobile development and development using React Native. We also touch upon where they differ and how to bridge the gaps. Read on.

A brief introduction to React Native

Let’s briefly set the context first. We will briefly touch upon what React Native is and how it differs from earlier hybrid frameworks.

React Native is a popular JavaScript framework that Facebook has created. You can use this open-source framework to code natively rendering Android and iOS mobile apps. You can use it to develop web apps too.

Facebook has developed React Native based on React, its JavaScript library. The first release of React Native came in March 2015. At the time of writing this article, the latest stable release of React Native is 0.62.0, and it was released in March 2020.

Although relatively new, React Native has acquired a high degree of popularity. The “Stack Overflow Developer Survey 2019” report identifies it as the 8th most loved framework. Facebook, Walmart, and Bloomberg are some of the top companies that use React Native.

The popularity of React Native comes from its advantages. Some of its advantages are as follows:

  • Performance: It delivers optimal performance.
  • Cross-platform development: You can develop both Android and iOS apps with it. The reuse of code expedites development and reduces costs.
  • UI design: React Native enables you to design simple and responsive UI for your mobile app.
  • 3rd party plugins: This framework supports 3rd party plugins.
  • Developer community: A vibrant community of developers support React Native.

Why React Native is fundamentally different from earlier hybrid frameworks

Are you wondering whether React Native is just another of those hybrid frameworks like Ionic or Cordova? It’s not! React Native is fundamentally different from these earlier hybrid frameworks.

React Native is very close to native. Consider the following aspects as described on the React Native website:

  • Access to many native platforms features: The primitives of React Native render to native platform UI. This means that your React Native app will use many native platform APIs as native apps would do.
  • Near-native user experience: React Native provides several native components, and these are platform agnostic.
  • The ease of accessing native APIs: React Native uses a declarative UI paradigm. This enables React Native to interact easily with native platform APIs since React Native wraps existing native code.

Due to these factors, React Native offers many more advantages compared to those earlier hybrid frameworks. We now review them.

#android app #frontend #ios app #mobile app development #benefits of react native #is react native good for mobile app development #native vs #pros and cons of react native #react mobile development #react native development #react native experience #react native framework #react native ios vs android #react native pros and cons #react native vs android #react native vs native #react native vs native performance #react vs native #why react native #why use react native

Mathew Rini

1615544450

How to Select and Hire the Best React JS and React Native Developers?

Since March 2020 reached 556 million monthly downloads have increased, It shows that React JS has been steadily growing. React.js also provides a desirable amount of pliancy and efficiency for developing innovative solutions with interactive user interfaces. It’s no surprise that an increasing number of businesses are adopting this technology. How do you select and recruit React.js developers who will propel your project forward? How much does a React developer make? We’ll bring you here all the details you need.

What is React.js?

Facebook built and maintains React.js, an open-source JavaScript library for designing development tools. React.js is used to create single-page applications (SPAs) that can be used in conjunction with React Native to develop native cross-platform apps.

React vs React Native

  • React Native is a platform that uses a collection of mobile-specific components provided by the React kit, while React.js is a JavaScript-based library.
  • React.js and React Native have similar syntax and workflows, but their implementation is quite different.
  • React Native is designed to create native mobile apps that are distinct from those created in Objective-C or Java. React, on the other hand, can be used to develop web apps, hybrid and mobile & desktop applications.
  • React Native, in essence, takes the same conceptual UI cornerstones as standard iOS and Android apps and assembles them using React.js syntax to create a rich mobile experience.

What is the Average React Developer Salary?

In the United States, the average React developer salary is $94,205 a year, or $30-$48 per hour, This is one of the highest among JavaScript developers. The starting salary for junior React.js developers is $60,510 per year, rising to $112,480 for senior roles.

* React.js Developer Salary by Country

  • United States- $120,000
  • Canada - $110,000
  • United Kingdom - $71,820
  • The Netherlands $49,095
  • Spain - $35,423.00
  • France - $44,284
  • Ukraine - $28,990
  • India - $9,843
  • Sweden - $55,173
  • Singapore - $43,801

In context of software developer wage rates, the United States continues to lead. In high-tech cities like San Francisco and New York, average React developer salaries will hit $98K and $114per year, overall.

However, the need for React.js and React Native developer is outpacing local labour markets. As a result, many businesses have difficulty locating and recruiting them locally.

It’s no surprise that for US and European companies looking for professional and budget engineers, offshore regions like India are becoming especially interesting. This area has a large number of app development companies, a good rate with quality, and a good pool of React.js front-end developers.

As per Linkedin, the country’s IT industry employs over a million React specialists. Furthermore, for the same or less money than hiring a React.js programmer locally, you may recruit someone with much expertise and a broader technical stack.

How to Hire React.js Developers?

  • Conduct thorough candidate research, including portfolios and areas of expertise.
  • Before you sit down with your interviewing panel, do some homework.
  • Examine the final outcome and hire the ideal candidate.

Why is React.js Popular?

React is a very strong framework. React.js makes use of a powerful synchronization method known as Virtual DOM, which compares the current page architecture to the expected page architecture and updates the appropriate components as long as the user input.

React is scalable. it utilises a single language, For server-client side, and mobile platform.

React is steady.React.js is completely adaptable, which means it seldom, if ever, updates the user interface. This enables legacy projects to be updated to the most new edition of React.js without having to change the codebase or make a few small changes.

React is adaptable. It can be conveniently paired with various state administrators (e.g., Redux, Flux, Alt or Reflux) and can be used to implement a number of architectural patterns.

Is there a market for React.js programmers?
The need for React.js developers is rising at an unparalleled rate. React.js is currently used by over one million websites around the world. React is used by Fortune 400+ businesses and popular companies such as Facebook, Twitter, Glassdoor and Cloudflare.

Final thoughts:

As you’ve seen, locating and Hire React js Developer and Hire React Native developer is a difficult challenge. You will have less challenges selecting the correct fit for your projects if you identify growing offshore locations (e.g. India) and take into consideration the details above.

If you want to make this process easier, You can visit our website for more, or else to write a email, we’ll help you to finding top rated React.js and React Native developers easier and with strives to create this operation

#hire-react-js-developer #hire-react-native-developer #react #react-native #react-js #hire-react-js-programmer

Kaustav Hazra

1603479480

 Component Life Cycle in React

Every component in React goes through a lifecycle of events. You can think is of going through a cycle of birth, growth, and death the same as the picture below.

The phases are:

  • Initialization — Starting the journey of your component
  • Mounting — Birth of your component
  • Update — Growth of your component
  • Unmount — Death of your component

1. Initialization

This is the phase in which the component is going to start its journey. The developer has to define the props and initial state of the component. This is usually done inside the constructor method (see below to understand the initialization phase better).

#react #react-lifecycle-method #react-course #react-for-beginner #react-js-tutorials

Ellis Herbert

Ellis Herbert

1577948509

4 Best React Navbar Component for Your App

React navbar is a horizontal navigation component which apart from traditional, text links, might embed icons, dropdowns, avatars or search forms.

Here are 4 React navbar component that will help your application. Enjoy!

1. React Scrolling NavBar

This Repo is not actively maintained! Please do not use in professional environment!

This is a React navbar component based on react-scroll. While this component is good, it doesn’t support mobile well, especially when there are many items in navbar. That’s why we need another navbar design for more responsiveness, mobile friendliness.

React Scrolling NavBar

Github: https://github.com/lijunray/react-scrolling-nav

Download Link: https://github.com/lijunray/react-scrolling-nav/archive/master.zip

2. react-responsive-navbar

Navbar component that moves the navbar items to a dropdown, if they do not fit in the content area.

react-responsive-navbar

View Demo: https://opuscapita.github.io/react-responsive-navbar/

Github: http://github.com/OpusCapita/react-responsive-navbar

Download Link: https://github.com/OpusCapita/react-responsive-navbar/archive/master.zip

3. react-navbar

React.js component rendering a translatable menu bar with Twitter Bootstrap Navbar HTML markup. For example, for a menu structure like the that:

react-navbar

Github: https://github.com/ikr/react-navbar

Download Link: https://github.com/ikr/react-navbar/archive/master.zip

4. NavbarNative

A fully customizable Navbar component for React-Native.

It works for both iOS and Android!

This is image title

View Demo:

This is image title

Github: https://github.com/redbaron76/navbar-native

Download Link: https://github.com/redbaron76/navbar-native/archive/master.zip

#React #react-navbar #navbar-component #react-navbar-component

Ethan Hughes

Ethan Hughes

1577975746

10 Best React Loading Component for Your App

While instant feedback from an app or website is best, sometimes your product won’t be able to adhere to speed guidelines. The slow response may be due to poor internet connection or the operation process may take a long time. For such cases, the designer must reassure the user that:
The application is working according to their requirements and the actual process is still active.

If you are unable to shorten the process, you should at least try to make the wait pleasant for your users. Here are 10 react loading components for your react.js application

1. Create React Content Loader

Have you heard about react-content-loader? It’s a SVG component to create placeholder loading, like Facebook cards loading or also known as skeleton UI. So now you can use this online tool to create your own loader easily. You just need to draw using the canvas or code using the live editing!

Create React Content Loader

View Demo: https://danilowoz.com/create-content-loader/

Github: https://github.com/danilowoz/create-content-loader

Download Link: https://github.com/danilowoz/create-content-loader/archive/master.zip

2. react-loading

React-Loading is a React-based Loading animation component library includes many exquisite and beautiful loading components. It will effectively relieve the user’s anxiety when you give loading dynamics tips at the appropriate place and moment in your project. This component library supports on-demand loading, so pick a favorite Loading component now to enrich your project

react-loading

View Demo: http://139.196.82.33:8080/iframe.html?id=demo–demo

Github: https://github.com/sixiaodong123/react-loading

Download Link: https://github.com/sixiaodong123/react-loading/archive/master.zip

3. react-simple-infinite-loading

Someone pointed out the React implementation of the list was a bit complex. I figure out it was possible to write an abstraction for this particular case. Here it is!

This component aims to stay easy to use. If your use case needs more options I recommend using directly awesome libraries from Brian Vaughn listed in dependencies section.

react-simple-infinite-loading

View Demo: https://codesandbox.io/s/magical-shockley-vhkz8

Github: https://github.com/frinyvonnick/react-simple-infinite-loading

Download Link: https://github.com/frinyvonnick/react-simple-infinite-loading/archive/master.zip

4. react-pure-loaders

React Pure Loaders is a package that disponibilizes loaders for your Project. Those loaders are used as components, using color and a loading variables as properties.

The component expects the to receive the color as a string with the hexadecimal code and the loading as a boolean, that is true by default.

react-pure-loaders

View Demo: https://reactpureloaders.io/

Github: https://github.com/jameswlane/react-pure-loaders

Download Link: https://github.com/jameswlane/react-pure-loaders

5. react-loadcon

React component to manipulate the favicon, as a loading or progress indicator, for now. The idea of “Favicon as DOM” is under construction.

react-loadcon

View Demo: https://foreseaz.github.io/react-loadcon/

Github: https://github.com/foreseaz/react-loadcon

Download Link: https://github.com/foreseaz/react-loadcon/archive/master.zip

6. React Nested Loader

The easiest way to manage loaders/errors inside a button. NOT an UI lib.

  • Manage loading/error state of nested views/buttons triggering async actions
  • Not an UI lib, you provide the UI. Works with ReactNative.
  • No boilerplate at all, no need to use setState/Redux

React Nested Loader

View Demo: https://codesandbox.io/s/w640yv5p9w

Github: https://github.com/slorber/react-nested-loader

Download Link: https://github.com/slorber/react-nested-loader/archive/master.zip

7. react-wait

react-wait is a React Hook helps to manage multiple loading states on the page without any conflict. It’s based on a very simple idea that manages an Array of multiple loading states. The built-in loader component listens its registered loader and immediately become loading state.

react-wait

View Demo: https://codesandbox.io/s/y3w5v5lk0j

Github: http://github.com/f/react-wait

Download Link: https://reactjsexample.com/complex-loader-management-hook-for-react/

8. React Redux Loading Bar

A React component that provides Loading Bar (aka Progress Bar) for long running tasks.

Consists of:

  • React component — displays loading bar and simulates progress
  • Redux reducer — manages loading bar’s part of the store
  • (optional) Redux middleware — automatically shows and hides Loading Bar for actions with promises

React Redux Loading Bar

View Demo: https://mironov.github.io/react-redux-loading-bar/

Github: http://github.com/mironov/react-redux-loading-bar

Download Link: https://github.com/mironov/react-redux-loading-bar/archive/master.zip

9. Material UI Image

Images are ugly until they’re loaded. Materialize it with material image! It will fade in like the material image loading pattern suggests.

Material UI Image

View Demo: https://mui.wertarbyte.com/#material-ui-image

Github: http://github.com/TeamWertarbyte/material-ui-image

Download Link: https://github.com/TeamWertarbyte/material-ui-image/archive/master.zip

10. React Lazy Load Image Component

React Component to lazy load images and other components/elements. Includes a HOC to track window scroll position to improve performance.

React Component to lazy load images and components using a HOC to track window scroll position.

React Lazy Load Image Component

View Demo: https://www.albertjuhe.com/react-lazy-load-image-component/

Github: http://github.com/Aljullu/react-lazy-load-image-component

Download Link: https://github.com/Aljullu/react-lazy-load-image-component/archive/master.zip

#loading #react-loading #react-loading-component #react #react-js