It's a JavaScript Library for building User Interfaces.
Created by Facebook
Stands for Model, View, Controller.
Software architectural pattern for implementing user interfaces.
Model: Is where the application's data is stored. The model doesn't have knowledge about views or controllers.
View: What's presented to the user, and is how a user interacts with the application.
Controller: The glue between the model and view. Controllers update the view when the model changes, and update the model when the user manipulates the view.
Important: MVC architectures can vary significantly from this traditional definition.
An application architecture based on unidirectional data flow.
It's more of a pattern than a formal framework.
An in-memory representation of the real DOM, that allows you to keep expensive writes to the DOM, to a minimum.
React components contain the mark-up (JSX/HTML) necessary for rendering themselves.
We've all been conditioned to separate our functionality from our views, but if you think about it, they are actually intrinsically linked.
Markup, and the code that generates it, are intimately connected.
Display logic is often very complex, and using a templating language to express it, can become cumbersome as the application grows...
A reusable UI element with a well defined interface.
Possible examples: Like buttons, Navigation bar, Beamly user feed, Feed item, Tweet, Drop-down menu, Image upload, Beamly search, Auto suggest input, Carrrrrrrousel.
"React encourages the creation of small self-contained components. If you're attempting to traverse the DOM, outside of your component, you're probably doing something wrong!"
<input type="text" ref="myTextInput" />
this.refs
property to obtain references to things, similar to jQuery's $(el).find();
:
var myTextInput = this.refs.myTextInput;
findDOMNode
method:
var domNode = React.findDOMNode(myTextInput);
Once a component has been loaded into the DOM, it's possible to use jQuery if necessary:
componentDidMount() {
var $ = require('jquery');
var myTextInput = this.refs.myTextInput;
var domNode = React.findDOMNode(myTextInput);
var $input = $(domNode);
$input.animate({
opacity: 0.25,
left: '+=50'
}, 5000, function () {
$(this).hide();
});
}
Or... use the component as the starting point via this
:
componentDidMount() {
var $ = require('jquery');
var reactComponentNode = React.findDOMNode(this); // <--
var $component = $(reactComponentNode);
var $body = $component.closest('body'); // DON'T DO THIS!
$body.css({ backgroundColor: '#000' });
var $input = $component.find('input[ref="myTextInput"]');
$input.fadeOut(2000);
}
// app.js
var React = require('react');
var SomeConponent = require('./someConponent');
var ReactApp = React.createClass({
render() {
return (<SomeConponent />);
}
});
module.exports = ReactApp;
// server.js
var React = require('react');
var express = require('express');
var appComponent = require('../public/js/components/app');
var ReactApp = React.createFactory(appComponent);
var app = express();
app.get('/some-conponent/:id', function(req, res) {
var html = React.renderToString(
ReactApp()
);
res.end(html);
});
Facebook states 130+ companies / apps
Instagram, Atlassian, BBC, Codecademy, Dropbox, Flipboard, Imgur, Khan Academy , Netflix, Reddit, The New York Times, Uber, WhatsApp, Wired, Yahoo, Zendesk, Atom Editor, Brackets Editor
But Facebook use it, so you know it can scale
Try it for size with a Todo MVC app
Time will tell...
As experienced software engineers at Beamly, we don’t want to be tied down by a framework, we want to be empowered to make our own decisions about the components we use to build our applications.