Tuesday, March 7, 2017

Introduction to Animations in React

In the last couple of React tutorials, you got familiar with basic React concepts like JSX, routing, and forms. In this tutorial, we'll take it to the next level and try to understand animations in React. 

Getting Started

Create a directory called ReactAnimations. Navigate to the directory and initiate the project using Node Package Manager or npm.

Install react and react-dom to the project. 

We'll be using webpack module bundler for this project. Install webpack and webpack development server.

Install the babel package to convert JSX syntax to JavaScript in our project.

Create a configuration file required by webpack-dev-server where we'll define the entry file, output file, and the babel loader. Here is how webpack.config.js looks:

Create an index.html file where the application will be rendered. Here is how it looks:

Create a file called app.js. Inside app.js import the required react libraries as shown:

Create a stateless component called Home which renders a H1 tag.

Render the Home component inside the app element in the index.html page. Here is how app.js looks:

Save the above changes and start the webpack server. You should have your app running at http://localhost:8080/index.html.

Animations in React

React provides a number of add-on utilities for creating React apps. TransitionGroup and CSSTransitionGroup are the APIs provided for animation.

From the official documentation,

The ReactTransitionGroup add-on component is a low-level API for animation, and ReactCSSTransitionGroup is an add-on component for easily implementing basic CSS animations and transitions.

Appear Animation

Let's start by trying out a simple animation in React. Install the react-addons-css-transition-group to the project.

Import ReactCSSTransitionGroup inside the app.js file.

Inside the Home component that you created, wrap up the h2 tag inside the ReactCSSTransitionGroup tag.

Using the ReactCSSTransitionGroup tag, you have defined the portion where animation would take place. You have specified a name for the transition using transitionName. You have also defined whether the transition appear, enter and leave should happen or not.

Using the transition name defined inside the ReactCSSTransitionGroup, you'll define the CSS classes which would be executed on appear and when in active state. Add the following CSS style to the index.html page.

As you would have noticed, you need to specify the animation duration both in the render method and in the CSS. It's because that's how React knows when to remove the animation classes from the element and when to remove the element from the DOM.

Save the above changes and refresh the page. Once the page has loaded, within a few seconds you should be able to see the animated text.

Enter/Leave Animation

To get a better understanding of the enter and leave animation, we'll create a small React application. The app would have an input text box to enter the name. You'll see how to add the enter animation when a name is added to the list. 

Inside app.js, create a new class called App.

Initialize a data list and a name variable inside the initial state of the component.

Inside the render portion of the App component, place an input text box for entering the name and a button to add the name to the array list.

Define the input handleChange event and the add event inside the App component.

The handleChange event sets the value of the input text box to the name variable. Here is how the add method looks:

Inside the add method, the entered name and a unique ID is pushed to the data array list.

Bind the handleChange and add method in the App component's constructor.

You'll be displaying the entered names inside a list. Modify the render HTML code to add the list.

To animate the newly added items, we'll add the ReactCSSTransitionGroup tag over the li elements.

Add the following CSS transition style to the index.html page. 

Here is the complete App component:

Save the above and refresh the page. Enter a name and enter the add button, and the item should be added to the list with animation.

Similarly, the leave animation can also be implemented in the above code. Once the delete functionality has been implemented in the application, add the leave and leave-active class to the index.html. Set the transitionLeave to True in the ReactCSSTransitionGroup tag in the render method, and you should be good to go. 

Wrapping It Up

In this tutorial, you saw how to get started with using animations in React. You created a simple React app and saw how to implement the appear and enter animation. For in-depth information on animations in React, I would recommend reading the official documentation.

The source code from this tutorial is available on GitHub.

Over the last couple of year, React has grown in popularity. In fact, we’ve a number of items in the marketplace that are available for purchase, review, implementation, and so on. If you’re looking for additional resources around React, don’t hesitate to check them out.

Do let us know your thoughts in the comments below. Have a look at my Envato Tuts+ instructor page for more tutorials on React and related web technologies.


by Roy Agasthyan via Envato Tuts+ Code

5 Ways to Use Facebook Messenger Bots for Your Business

Do your customers message you with questions, comments, or complaints on Facebook? Want to automate the most common customer interactions? Customers expect lightning-fast responses from businesses on Facebook. Chatbots can help you deliver the right answer the moment a customer asks. In this article, you’ll discover five types of Facebook Messenger bots your business can [...]

This post 5 Ways to Use Facebook Messenger Bots for Your Business first appeared on .
- Your Guide to the Social Media Jungle


by Ana Gotter via

Volta Footwear

Bold as a sneaker, Classic as a design piece.
by via Awwwards - Sites of the day

Monday, March 6, 2017

DESCENTE 2017 SS COLLECTION

DESCENTE 2017 Spring & Summer New Collection. And special contents blackout website. It’s getting closer, day by day.


by csreladm via CSSREEL | CSS Website Awards | World best websites | website design awards | CSS Gallery

Upperdog

Upperdog, a team of digital fanatics and knowledge seekers wanted to create a cutting-edge site. The result: a website built entirely in Polymer.


by csreladm via CSSREEL | CSS Website Awards | World best websites | website design awards | CSS Gallery

Tony & Jeanette

For Tony & Jean we branded their wedding and carried the look and feel through out all things that were related to the wedding.


by csreladm via CSSREEL | CSS Website Awards | World best websites | website design awards | CSS Gallery

25 Black Hat SEO Techniques That Are Killing Your Website [Infographic]

As Google constantly amends their ranking algorithms website owners continue to look for creative ways to make their website rank higher and stand out in the serps. But despite Google’s warnings that certain techniques are not allowed we still see a number of black hat techniques in use today. To...

[ This is a content summary only. Visit our website http://ift.tt/1b4YgHQ for full links, other content, and more! ]

by Irfan Ahmad via Digital Information World