Convert class to stateless function component

by Ruslan Aliyev

HTML

<script src="https://fb.me/react-0.14.3.js"></script>
<script src="https://fb.me/react-dom-0.14.3.js"></script>
<div class="example">example 1
  <div id="app"></div>
</div>

<div class="example">example 2
  <div id="app2"></div>
</div>

<div class="example">example 3
  <div id="app3"></div>
</div>

<div class="example">example 4
  <div id="app4"></div>
</div>

CSS

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background-color: #ffffff;
  font-family: Helvetica, Arial, sans-serif;
  text-align: center;
}

.example {
  margin: 10px 10px 20px 10px;
  border: 1px solid #CCC;
  border-radius: 8px;
  padding: 15px;
}

.big {
  font-size: 100px;
}

#app {
  position: relative;
  height: 100%;
  width: 100%;
  padding-top: 10px;
}

#app div {
  width: 100%;
}

#app div div {
  position: absolute;
  height: 100%;
}

#app div div div {
  position: relative;
  height: auto;
}

h1 {
  margin-left: 5%;
  margin-right: 5%;
}

ul {
  list-style-type: none;
  padding: 0;
}

img {
  width: 300px;
}

nav a {
  margin: 12px;
  text-transform: uppercase;
  font-size: 10px;
}

button {
  -webkit-transition-duration: 0.1s;
  /* Safari */
  transition-duration: 0.1s;
  background-color: #F4595B;
  border-radius: 8px;
  border-bottom: 4px solid #C24648;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  font-family: 'Oxygen', sans-serif;
  letter-spacing: 2px;
}

button:hover {
  background-color: #FF7375;
  border: none;
  border-radius: 8px;
  border-bottom: 4px solid #C24648;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  font-family: 'Oxygen', sans-serif;
  letter-spacing: 2px;
}

button:active {
  background-color: #C24648;
  border: none;
  border-radius: 8px;
  border-bottom: 4px solid #C24648;
  color: #CCC;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  font-family: 'Oxygen', sans-serif;
  letter-spacing: 2px;
}

Babel + JSX

// This is already being required by JSFiddle
//var React = require('react'); 
//var ReactDOM = require('react-dom');

//a stateless functional component in action
// A component class written in the usual way:
var MyComponentClass = React.createClass({
  render: function(){
    return <h1>Hello world</h1>;
  }
});

// The same component class, written as a stateless functional component:
function MyComponentClass () {
  return <h1>Hello world</h1>;
}

// Works the same either way:
ReactDOM.render(
	<MyComponentClass />,
	document.getElementById('app')
);

//and again
/* OLD 
var Friend = React.createClass({
	render: function () {
		return <img src='https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-octopus.jpg' />;
	}
});
*/

// NEW
function Friend () {
  return <img src='https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-octopus.jpg' />;
}

ReactDOM.render(
	<Friend />,
	document.getElementById('app2')
);

// passing props to a stateless component
// Normal way to display a prop:
var MyComponentClass = React.createClass({
  render: function () {
    return <h1>{this.props.title}</h1>;
  }
});

// Stateless functional component way to display a prop:
function MyComponentClass (props) {
  return <h1>{props.title}</h1>;
}

// Normal way to display a prop using a variable:
var MyComponentClass = React.createClass({
  render: function () {
  	var title = this.props.title;
    return <h1>{title}</h1>;
  }
});

// Stateless functional component way to display a prop using a variable:
function MyComponentClass (props) {
	var title = props.title;
  return <h1>{title}</h1>;
}

ReactDOM.render(
	<MyComponentClass />,
	document.getElementById('app3')
);


// GuineaPigs.js
//var React = require('react');

function GuineaPigs (props) {
  var src = props.src;
  return (
    <div>
      <h1>Cute Guinea Pigs</h1>
      <img src={src} />
    </div>
  );
}

//module.exports = GuineaPigs;

// GuineaPigsContainer.js
//var GuineaPigs =...