Skip to content

Instantly share code, notes, and snippets.

@sibinx7
Last active June 27, 2018 05:15
Show Gist options
  • Save sibinx7/2bdc05222c3d9a6dafa903e71890e4d6 to your computer and use it in GitHub Desktop.
Save sibinx7/2bdc05222c3d9a6dafa903e71890e4d6 to your computer and use it in GitHub Desktop.
Learn React and React resources

Why is React so popular?

React helps developers build applications by helping manage application state. It's simple, declarative, and composable. React is not a traditional MVC framework. React is really only interested in building user interfaces. Some have called it the "V" in MVC, but that's a little misleading. React sees the world much differently from traditional MVC frameworks. As more application logic started moving toward the client, many application developers wanted to apply some kind of structure to their front-end JavaScript. So we started applying a paradigm that we understood from the server (MVC) and apply it to the browser. The problem with this approach is that the browser environment is very different from the server. React acknowledges that client-side applications are really a collection of UI components that should react to events like user interaction.

React encourages building applications out of self-contained, reusable components that only care about a small piece of the UI. Many other frameworks attempt to do this such as Angular. React is different in that it enforces uni-directional data flow from parent component to child component. This makes debugging much easier. Most time spent working on applications is spent on debugging, so while React is more verbose that other libraries/frameworks, in the end it saves a lot of time. In a framework like Angular, if there's a bug it can be hard to figure out where it's coming from: is it in the view? The model? The controller? The directive? The directive controller? Data in Angular flows in many different directions, making it hard to reason about that state of your application. In React, when there is a bug, you can quickly determine where the bug originated from, since data only moves in one direction. If there is a bug, you just trace the direction of the data until you find the culprit.

Popular Packages

React and Redux tutorials

Video Tutorials

Inline Condition to render React Components

 return (
    <div>
      <h1>Hello!</h1>
      {unreadMessages.length > 0 &&
        <h2>
          You have {unreadMessages.length} unread messages.
        </h2>
      }
    </div>
  );

Note:

condition && statement return statement if condition true, false if condition false

 return (
    <div>
      {isLoggedIn ? (
        <LogoutButton onClick={this.handleLogoutClick} />
      ) : (
        <LoginButton onClick={this.handleLoginClick} />
      )}
    </div>
  );

Load image assets in React component, background url etc...

      {
        test: /\.(jpe?g|png|gif|svg)$/i,
        loaders: [
          'file?hash=sha512&digest=hex&name=[hash].[ext]',
          'url-loader?limit=20000',
          'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'
        ],
      }

Webpack 2

loaders: [
  {
    test: /\.(gif|png|jpe?g|svg)$/i,
    loaders: [
      'file-loader',
      {
        loader: 'image-webpack-loader',
        query: {
          progressive: true,
          optimizationLevel: 7,
          interlaced: false,
          pngquant: {
            quality: '65-90',
            speed: 4
          }
        }
      }
    ]
  }
]

Synthentic and Native Events

  • event.persist() can be used to cancel synthetic event

React Redux Authetication

Heroku build packs

React and Redux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment