CodeX
Published in

CodeX

React Tutorial: How to build the Instagram UI with React

Image Source: Author
  • Prerequisites
  • Setting up your React Project
  • Create UI Components
  • Upgrading your app with properties
  • Next steps for your Instagram app

Prerequisites

node --version
npm --version
npm install -g create-react-app

Setting up your React project

create-react-app instagram-clone
cd instagram-clone
npm start
Image Source: Author

Create UI components

Header component

cd src
mkdir components && cd components
mkdir Header && cd Header
touch index.js
// src/components/Header/index.js    import React from "react";    class Header extends React.Component{        render(){            return (               <nav className="Nav">                 <div className="Nav-menus">                   <div className="Nav-brand">                     <a className="Nav-brand-logo" href="/">                       Instagram                     </a>                   </div>                 </div>               </nav>           );        }       }    export default Header;
touch Header.css
/* src/components/Header/Header.css */    i.Nav {      background-color: #fff;      border-bottom: 1px solid rgba(0, 0, 0, 0.0975);      position: fixed;      top: 0;      width: 100%;      z-index: 2;      -webkit-transition: height 0.2s ease-in-out;      transition: height 0.2s ease-in-out;      height: 77px;    }    .Nav-menus {      display: flex;      flex-direction: row;      height: 77px;      width: 70%;      margin: 0 auto;      padding: 26px 40px;    }    .Nav-brand-logo {      display: block;      background-position: -176px 0px;      background-image: url(../../logo.png);      background-size: 405px 379px;      background-repeat: no-repeat;      height: 35px;      width: 176px;      text-indent: -1000%    }
// src/components/Header/index.js    import React from "react";    import "./Header.css";    class Header extends React.Component{        render(){            return (               <nav className="Nav">                 <div className="Nav-menus">                   <div className="Nav-brand">                     <a className="Nav-brand-logo" href="/">                       Instagram                     </a>                   </div>                 </div>               </nav>           );        }       }    export default Header;
// src.App.js    import React, { Component } from 'react';    import './App.css';    import Header from './components/Header';    class App extends Component {      render() {        return (          <Header />        );      }    }    export default App;
Image Source: Author

Post Component

cd src/componentsmkdir Post && cd Post
touch index.js
// src/components/Post/index.js    import React, { Component } from "react";    class Post extends Component {      render() {        return <article className="Post" ref="Post">            <header>              <div className="Post-user">                <div className="Post-user-profilepicture">                  <img src="https://t4.ftcdn.net/jpg/02/19/63/31/360_F_219633151_BW6TD8D1EA9OqZu4JgdmeJGg4JBaiAHj.jpg" alt="John D. Veloper" />                </div>                <div className="Post-user-nickname">                  <span>John Doe</span>                </div>              </div>            </header>            <div className="Post-image">              <div className="Post-image-bg">                <img alt="Icon Living" src="[https://cdn-images-1.medium.com/max/1200/1*dMSWcBZCuzyRDeMr4uE_og.png]" />              </div>            </div>            <div className="Post-caption">              <strong>John D. Veloper </strong> Loving Educative!            </div>          </article>;        }    }    export default Post;
  • Post Header - which shows the profile picture and username
  • Post Content - displays the posted image
  • Post Caption - displays the username and the caption
touch Post.css
/* src/components/Post/Post.css */    .Post {      border-radius: 3px;      border: 1px solid #e6e6e6;      background-color: #fff;      margin-bottom: 60px;      margin-left : 20%;      margin-right: 20%;    }    .Post-user {      display: flex;      padding: 16px;      align-items: center;    }    .Post-user-profilepicture {      width: 30px;      height: 30px;    }    .Post-user-profilepicture img {      width: 100%;      height: 100%;      border-radius: 50%;    }    .Post-user-nickname {      margin-left: 12px;      font-family: 'PT Sans', sans-serif;      font-weight: bold;    }    .Post-image-bg {      background-color: #efefef;    }    .Post-image img {      display: block;      width: 100%;    }    .Post-caption {      padding: 16px 16px;    }    .Post-caption strong {      font-family: 'PT Sans', sans-serif;      font-weight: bold;    }    .vjs-fade-out {      display: none;      visibility: hidden;      opacity: 0;    }
import "./Post.css";
// src/App.js    import Post from './components/Post';    class App extends Component {      render() {        return (          <div>            <Header />            <div>              <Post />            </div>          </div>        );      }    }    export default App;
Image Source: Author

Upgrading your app with properties

// src/components/Post/index.js    import React, { Component } from "react";    import "./Post.css";    class Post extends Component {        constructor(props){            super(props);        }      render() {        const nickname = this.props.nickname;        const profilepicture= this.props.profilepicture;        const image = this.props.image;        const caption = this.props.caption;        return (          <article className="Post" ref="Post">            ...                <img src={profilepicture} alt={nickname} />            ...                   <span>{nickname}</span>            ...                <img alt={caption} src={image} />            ...              <strong>{nickname}</strong>{caption}            ...          </article>        );      }    }    export default Post;
// src/App.js    import React, { Component } from 'react';    import './App.css';    import Header from './components/Header';    import Post from './components/Post';    class App extends Component {      render() {        return <div className="App">            <Header />            <section className="App-main">              <Post nickname="John D. Veloper" profilepicture="https://t4.ftcdn.net/jpg/02/19/63/31/360_F_219633151_BW6TD8D1EA9OqZu4JgdmeJGg4JBaiAHj.jpg" caption="Loving Educative!" image="https://cdn-images-1.medium.com/max/1200/1*dMSWcBZCuzyRDeMr4uE_og.png" />            </section>          </div>;      }    }    export default App;

Next steps for your Instagram app

  • Back-end fetch integration with Graph QL or Firebase
  • Add real-time an Instagram Story feature
  • Create tabs and account pages that pull previous posts
  • Add login authentication with Firestore
  • Add an Instagram Messenger feature with emoji support

--

--

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
The Educative Team

Master in-demand coding skills with Educative’s hands-on courses & tutorials.