Header component exercise

UPDATE: Ok, this is even stranger. haha. Sometimes when making a new styled component, it will not work out right and have some kind of bug and then the is not a function error will pop-up, I could fix it this time by deleting the declaration and trying it again from scratch. One thing I could observe was, if the declaration did not work out the syntax highlighting is different from when it is working, ALTHOUGH, the exaaactly same code has been written. :exploding_head: :thinking: :man_facepalming:
So for future readers, try to delete the styled component and give it another go. Try to make your styled component look like this:

StyledCompRight

Instead of this:
StyledCompProblem

StyledProblem

Still having the issue with creating new styled components. dependencies are checked

package.json

"dependencies": { "@testing-library/jest-dom": "^5.11.9", "@testing-library/react": "^11.2.5", "@testing-library/user-event": "^12.8.3", "react": "^17.0.1", "react-dom": "^17.0.1", "react-scripts": "4.0.3", "styled-components": "^5.2.1", "uuid": "^8.3.2", "web-vitals": "^1.1.1" },

It is quite strange, as it works in coin.jsx but will not work if I try to create another styled component for header.jsx. Still saying Is not a function. It’s is driving me a little crazy I must admit. How can it work for one file but not the other in the same project?
:thinking:

So I solved it without styled components for the header.

header.jsx
import React, { Component } from 'react'
import logo from '../../logo.svg';



export default class Header extends Component {
    render() {
        return (
            <header>
          <img src={logo} className="App-logo" alt="logo" />
          
            <h1 className="App-Title">Coin Exchange</h1>
        </header>
        )
    }
}


App.jsx
import Header from './components/Header/Header';
.
.
.
.
render(){

    return (
      <div className="App">
        <Header />
        <h2><AccountsBalance amount={this.state.balance} /></h2>
        <Coinlist coinData = {this.state.coinData} />
        
      </div>
    );

  }

I guess your spelling of styled.header is wrong thus it gives out that error. Please provide us with the GitHub link so that we can debug the issue and pin point it.

Happy Learning!

//CoinHeader import at top of app.js
import CoinHeader from './components/CoinHeader/CoinHeader';
//render in app.js
 render(){
    return (
      <div className="App">
        <CoinHeader/>
        <AccountBalance amount={this.state.balance}/>
        <CoinList coinData={this.state.coinData}/>
      </div>
    );
  }
//Then in CoinHeader.jsx
import React, { Component } from 'react'
import logo from '../../logo.svg';
export default class CoinHeader extends Component {
    render() {
        return (
        <header className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h1 className="App-title">
            The Loop Exchange
          </h1>
        </header>
        )
    }
}
2 Likes

App Class Return

return (
<div className=“App”
<Header /
<AccountBalance amount={this.state.balance} /
<CoinList coinData={this.state.coinData} /
</div
);

Header Component

import React, { Component } from ‘react’
import logo from ‘…/…/logo.svg’;

export default class Header extends Component {
render() {
return (
<div
<header className=“App-header”
<img src={logo} alt=“React logo” className=“App-logo” /
<h1 className=“App-title”</h1
<h1
Coin Exchange
</h1
</header
</div
)
}
}

2 Likes
app.js
import React from 'react';

import CoinList from './components/CoinList/CoinList';

import AccountBalance from './components/AccountBalance/AccountBalance';

import Header from './components/Header/Header';

import styled from 'styled-components';

const Content = styled.div`

text-align: center;

  background-color: rgb(82, 79, 79);

  color: rgb(180, 178, 19);

`;

class App extends React.Component {

  constructor(props) {

    super(props);

    this.state = {

      balance: 10000,

      coinData: [

        {

          name: 'Bitcoin',

          ticker: 'Btc',

          price: 9999.99

        },

        {

          name: 'Ethereum',

          ticker: 'Eth',

          price: 2999.99

        },

        {

          name: 'Tether',

          ticker: 'USDT',

          price: 1.0

        },

        {

          name: 'Ripple',

          ticker: 'XRP',

          price: 1.3

        },

        {

          name: 'Bitcoin Cash',

          ticker: 'BCH',

          price: 298.99

        }

      ]

    }

  }

  render() {

    return (

      <Content>

        <Header />

        <AccountBalance amount = {this.state.balance} />

       <CoinList coinData={this.state.coinData} />

      </Content>

    );

  }

  

}

export default App;
Header.jsx
import React, { Component } from 'react';

import styled from 'styled-components';

import logo from '../../logo.svg';

const Head = styled.header`

background-color: #282c34;

  min-height: 20rem;

  display: flex;

  flex-direction: row;

  align-items: center;

  justify-content: flex-start;

  font-size: 36px;

`;

const Img = styled.img`

height: 8rem;

pointer-events: none;

`;

const H1 = styled.h1`

font-size: 4rem;

`;

export default class Header extends Component {

    render() {

        return (

            <Head>

           <Img src={logo} alt="React logo" />

            <H1>

              Coin Exchange 

            </H1>

          </Head>

        )

    }

}
Coinlist.jsx
import React, { Component } from 'react';

import PropTypes from 'prop-types';

import styled from 'styled-components';

const CoinRow = styled.td`

border: 1px solid;

    width: 25vh;

`;

export default class Coin extends Component {

    constructor(props) {

        super(props);

        this.state = {

            price: this.props.price

        }

        this.handleClick = this.handleClick.bind(this);

    }

    handleClick(event) {

        // Prevent the default action of submitting the form

        event.preventDefault();

        const randomPercentage = 0.995 + Math.random() * 0.01;

        this.setState( function(oldState) {

            return {

                price: oldState.price * randomPercentage

            };

        });

    }

    render() {

        return (

            <tr>

              <CoinRow>{this.props.name}</CoinRow>

              <CoinRow>{this.props.ticker}</CoinRow>

              <CoinRow>${this.state.price}</CoinRow>

              <CoinRow>

                  <form action="#" method="POST">

                  <button onClick={this.handleClick}>Refresh</button>

                  </form>            

              </CoinRow>

            </tr>

           );

    }

}

Coin.propTypes = {

    name: PropTypes.string.isRequired,

    ticker: PropTypes.string.isRequired,

    price: PropTypes.number.isRequired

}
2 Likes

On App.js

import React from 'react';
import './App.css';
import HeaderID from './components/Header/Header'
import CoinList from './components/CoinList/CoinList';
import AccountBalance from './components/AccountBalance/AccountBalance';
import { v4 as uuidv4 } from 'uuid';

I created a component called it Header
import React, { Component } from 'react';

import logo, { ReactComponent } from '../../logo.svg';

export default class Header extends Component {
    render() {
        return (
            <header className="App-header">
          <img src={logo} alt="React Logo" className = 'App-logo'/>
          <h1 className="App-title">
            Coin Exchange
          </h1>
          
        </header>
        )
    }
}
2 Likes

I have a question, I can write the use styled components but I don’t know how to do it with animations. I’ve read the styled components docs but I can’t make it work, sorry for the trouble.

I also imported this: import styled, { css, keyframes } from 'styled-components';

Anyway, here are my codes

AppHeader.jsx
import React, { Component } from 'react';
import logo from '../../logo.svg';
import styled, { css, keyframes } from 'styled-components';

const Header = styled.header`
    background-color: #030011;
    min-height: 20vh;
    display: flex;
    flex-direction: column;
    align-items: inherit;
    justify-content: flex-start;
    color: white;
`;

const H1 = styled.h1`
    font-size: 4rem;
    font-style: oblique;
    font-family: Georgia, 'Times New Roman', Times, serif;
`;

const P = styled.p`
    font-size: 1.5rem;
    font-style: normal;
    font-family: 'Lucida Sans Regul';
`;

const Image = styled.img`
    height: 20vmin;
    pointer-events: none;
`;

/*
const rotate = keyframes`
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
`;


const Rotate = Image => css`
    ${rotate} ${Image} 15s linear infinite;
`;
*/

export default class AppHeader extends Component {
    render() {
        return (
            <Header>
            <Image src={logo} className="App-logo" alt="React logo" />
            <H1>
              Coin Exchange
            </H1>
            <P className = "App-subtitle">
              by: Xyz Fiegalan
            </P>
          </Header>
        );
    }
}

App.js
import React from 'react';
import './App.css';
import AccountBalance from './components/AccountBalance/AccountBalance';
import CoinList from './components/CoinList/CoinList';
import AppHeader from './components/AppHeader/AppHeader';
import styled from 'styled-components';

const Div = styled.div`
  text-align: center;
  background-color: lightblue;
`;

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      balance: 10000,
      coinData: [
        {
          name: 'Bitcoin',
          ticker: 'BTC',
          price: 60000
        },
        {
          name: 'Ethereum',
          ticker: 'ETH',
          price: 2500
        },
        {
          name: 'Cardano',
          ticker: 'ADA',
          price: 1.5
        },
        {
          name: 'Binance',
          ticker: 'BNB',
          price: 600
        }
      ]
    }
  }

  render () {
    return (
      <Div className="App">
        <AppHeader />
        <AccountBalance amount = {this.state.balance} />
        <CoinList coinData={this.state.coinData} /> 
      </Div>
    );
  }
}

/*
function App() {
  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="React logo" />
        <h1 className = "App-title">
          Coin Exchange
        </h1>
        <p className = "App-subtitle">
          by: Xyz Fiegalan
        </p>
      </header>

      <AccountBalance amount = {10000} />

      <table className = "coin-table">
        <thead>
          <tr>
            <TitleDetails>Name</TitleDetails>
            <TitleDetails>Ticker</TitleDetails>
            <TitleDetails>Price</TitleDetails>
          </tr>
        </thead>
        <tbody>
          <Coin name="Bitcoin" ticker="BTC" price ={60000}/>
          <Coin name="Ethereum" ticker="ETH" price ={2500}/>
          <Coin name="Cardano" ticker="ADA" price ={1.5}/>
          <Coin name="Binance" ticker="BNB" price = {600}/>
        </tbody>
      </table>
    </div>
  );
}
*/

export default App;

Coin.jsx
import React, { Component } from 'react'
import styled from 'styled-components';
import PropTypes from 'prop-types';

const RowDetails = styled.td`
    border: 2px solid burlywood;
    width: 25vh;
    background-color: white;
`;


export default class Coin extends Component {
    constructor(props) {
        super(props);
        this.state = {
            price: this.props.price
        }
        this.handleClick = this.handleClick.bind(this);
    }
 
    handleClick(event) {
    // Prevent the default action of submitting the form
        event.preventDefault();

        const randomPercentage = 0.995 + Math.random() * 0.01;
        this.setState( function(oldState) {
            return {
                price: oldState.price * randomPercentage
            };
        })
    }
    render() {
        return (
        <tr>
            <RowDetails>{this.props.name}</RowDetails>
            <RowDetails>{this.props.ticker}</RowDetails>
            <RowDetails>${this.state.price}</RowDetails>
            <RowDetails>
                <form action = "#" method = "POST">
                    <button onClick = {this.handleClick}>Refresh</button>
                </form>
            </RowDetails>
        </tr>
        )
    }
}

Coin.propTypes = {
    name: PropTypes.string.isRequired,
    ticker: PropTypes.string.isRequired,
    price: PropTypes.number.isRequired
}

CoinList.jsx
import React, { Component } from 'react';
import Coin from '../Coin/Coin';
import styled from 'styled-components';

const TitleDetails = styled.th`
    border: 2px solid burlywood;
    width: 25vh;
    background-color: black;
    color: white;
`;

const Table = styled.table`
    margin: 20px auto 20px auto;
    display: inline-block;
    font-size: 1.5rem;
`;

export default class CoinList extends Component {
    render() {
        return (
            <Table>
            <thead>
                <tr>
                <TitleDetails>Name</TitleDetails>
                <TitleDetails>Ticker</TitleDetails>
                <TitleDetails>Price</TitleDetails>
                </tr>
            </thead>
            <tbody>
                {
                this.props.coinData.map(({name, ticker, price}) =>
                    <Coin key={ticker} name={name} ticker={ticker} price={price} />
                    )
                }
            </tbody>
            </Table>
        )
    }
}

AccountBalance.jsx
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';

const Section1 = styled.section`
    margin: auto;
    box-shadow: 2px 2px 7px 1px black;
    background-color: rgb(253, 239, 218);
    float: center;
    font-size: 1.5rem;
    box-sizing: content-box;
    font-weight: bold;
`;

export default class AccountBalance extends Component {
    render() {
        return (
            <Section1 className = "balance">
              Current Balance is: {this.props.amount} USD
            </Section1>
        );
    }
}

AccountBalance.propTypes = {
    amount: PropTypes.number.isRequired
}
2 Likes
App.js :
AppHeader.jsx :
2 Likes

Hello Zsolt
on State Update Immutability video i did every thing but my coin price is not changing once i click on refresh. I console logged newCoinData saw that the price of my coin are changing but do not reflect on table data below is my code

import React from ‘react’;
import HeaderID from ‘./components/Header/Header’
import CoinList from ‘./components/CoinList/CoinList’;
import AccountBalance from ‘./components/AccountBalance/AccountBalance’;
import { v4 as uuidv4 } from ‘uuid’;
import styled from ‘styled-components’;

const Div = styled.div text-align: center; background-color: rgb(2, 2, 70); color: #cccccc;;

class App extends React.Component {
constructor(props){
super(props);
this.state = {
balance: 10000,
coinData: [
{
key: uuidv4(),
name: ‘BITCOIN’,
ticker: ‘BTC’,
price: 9999.99
},
{
key: uuidv4(),
name: ‘ETHERUM’,
ticker: ‘ETH’,
price: 299.99
},
{
key: uuidv4(),
name: ‘TETHER’,
ticker: ‘USDT’,
price: 1.00
},
{
key: uuidv4(),
name: ‘RIPPLE’,
ticker: ‘XRP’,
price: 0.20
}
/


/
]
}
this.handleRefresh = this.handleRefresh.bind(this);
}

handleRefresh (changevalueTicker) {

const newCoinData = this.state.coinData.map(function ({ticker,name,price,key}) {
  let newPrice = price;
  if(changevalueTicker === ticker){
    const ramdomPercentage = 0.995 + Math.random() * 0.01;
    newPrice = newPrice * ramdomPercentage;
  }

  return{
    key,
    name,
    ticker,
    price: newPrice
  }
});
//console.log(newCoinData);
this.setState(      
  {coinData : newCoinData}
  );

}

render(){

return (
  <Div className="App">
    <HeaderID/>
    <AccountBalance amount = {this.state.balance} />
    <CoinList handleRefresh={this.handleRefresh} coinData={this.state.coinData}  />
  </Div>
);

}

}

export default App;

Please create a codesandbox.io React project with all files or upload your code on GitHub.

Please also avoid copying source code here directly, because some characters are replaced by other characters.

As far as I can see, the contents of your App.js file is correct. Ask yourself how you use the handleRefresh function in the other file.

A good solution is to restart the whole task whenever you get stuck and you’ll see the extra confidence you get while going through the lessons.

1 Like

Here is link to my code on Github

https://github.com/chim4us/React

I will restart the project again

Thanks i have seen where the error is coming from
On Coin.jsx i did not change the coin row to props it was on state

Thanks so much for the advise

2 Likes

Exchange Header:

import React, { Component } from 'react'
import logo from '../../logo.svg';


export default class ExchangeHeader extends Component {
    render() {
        return (
            <div>
            <header className="App-header">
            <img src={logo} alt="React logo" className="App-logo"/>
            <h1 className="App-title">
                Coin Exchange
            </h1>
            </header>
            </div>
        )
    }
}

I am also not a fan of the styled components, compared to CSS.

2 Likes
import React, { Component } from 'react'
import logo from '../../logo.svg'
import styled from 'styled-components'

const H1 = styled.h1`
 font-size: 4rem;
`;

const Img = styled.img`
 height: 8rem;
 pointer-events: none;
`;

const Header1 = styled.header`
background-color: #282c34;
min-height: 10vh;
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;

color: white;
`;


export default class Header extends Component {
    render() {
        return (
            <Header1>
        <Img src={logo} alt="React logo"/>
          <p>
            <H1>Coin Exchange</H1>
          </p>
        </Header1>
        )
    }
}

1 Like

My solution:

Header.jsx

import React, { Component } from "react";
import logo from '../logo.svg';

export default class Header extends Component {
  render() {
    return (
      <header className='App-header'>
        <img src={logo} alt='React logo' className='App-logo' />
        <h1 className='App-title'>Coin Exchange</h1>
      </header>
    );
  }
}

App.js

  render(){
    return (
      <div className="App">
        <Header/>
        <AccountBalance amount={this.state.balance}/>
        <CoinList coinData={this.state.coinData}/>
      </div>
    );
  }
1 Like

App.js

render(){
    return (
      <AppDiv>
        <Header title= {this.state.pageTitle}/>
        <AccountBalance  amount = {this.state.amount}/>
        <CoinList coinData = {this.state.coinData}/>
      </AppDiv>
    );
  }

Header.jsx with styled components

import React, { Component } from 'react';
import logo from '../../logo.svg';
import styled , { keyframes } from 'styled-components';

const NewHead = styled.header`
    background-color: #000000;
    min-height: 25vh;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    color: white;
`;

const Applogospin = keyframes`
from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
`;

const NewLogo = styled.img`
  height: 20vmin;
  pointer-events: none;
  @media (prefers-reduced-motion: no-preference) {
    animation: ${Applogospin} infinite 20s linear;
}
`;

const NewTitle = styled.h1`
  font-size: 36px;
`;

export default class Header extends Component {
    render() {
        return (
            <NewHead>
                <NewLogo src={logo} alt="logo" />
                <NewTitle>
                   {this.props.title}
                </NewTitle>
            </NewHead>
        );
    }
}
1 Like

Admittedly I did Jump ahead and watch the video for bug fixing, I did get a module build error briefly that I found to be an interesting thing to learn about. I did enjoy the practice with styled components.

import React, { Component } from 'react';
import logo from './logo.svg';
import styled from 'styled-components';

const Img = styled.img`
height: 6rem;
    pointer-events: none;
`;

const H1 = styled.h1`
color:rgb(244, 248, 240);
`;

const Header = styled.header`
background-color: rgb(2, 1, 53);
    min-height: 20vh;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    font-size: calc(10px + 2vmin);
    color: white;
`

export default class ExchangeHeader extends Component {
    render() {
        return (
            <Header>
            <Img src={logo} alt="React Logo" />
            <H1>
              The Greatest Coin Exchange of All Time
            </H1>
          </Header>
        )
    }
}

1 Like

I’m having a tonne of trouble getting the compiler to find the logo module.
Everything works fine but when I added the logo to the ExchangeHeader.jsx file, it keeps giving me the following error:

./src/components/ExchangeHeader/ExchangeHeader.jsx
Module not found: Can't resolve '.../logo.svg'

When I removed the import and just included it as the path when calling the img, it renders, but gives an image placeholder.

Any help here would be so appreciated. I have no idea what’s wrong and have spent over an hour trying to figure it out.
p.s. each of the ExchangeHeader.jsx, CoinList.jsx and Coin.jsx files have their own folder in the components folder with a matching subfolder name.

Anyway, here’s my code!

App.js

import React from 'react';
import CoinList from './components/CoinList/CoinList';
import AccountBalance from './components/AccountBalance/AccountBalance';
import ExchangeHeader from './components/ExchangeHeader/ExchangeHeader';
import styled from 'styled-components';

const Applic = styled.div`
  text-align: center;
  background-color: rgb(24, 24, 71);
  color: #cccccc;
`

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      balance: 10000,
      coinData: [
        {
          name: "Bitcoin",
          ticker: "BTC",
          price: 9999.99
        },
        {
          name: "Ethereum",
          ticker: "ETH",
          price: 5000
        },
        {
          name: "Litecoin",
          ticker: "LTC",
          price: 2000
        }
      ]
    } 
  }
  render() {
    return (
      <Applic>
        <ExchangeHeader/>
        <AccountBalance amount = {this.state.balance} />
        <CoinList coinData = {this.state.coinData}/>
      </Applic>
    );
  }
}
    
export default App;

ExchangeHeader.jsx

import React, { Component } from 'react';
import styled from 'styled-components';
import logo from '.../logo.svg';

    const AppTitle = styled.h1`
    font-size: 4rem;
    `;

    const AppHeader = styled.header`
    background-color: #282c34;
    min-height: 20vh;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    color: white;
    `

    const AppLogo = styled.img`
    height: 8rem;
    pointer-events: none;
    `

    export default class ExchangeHeader extends Component {
        render() {
            return (
                <AppHeader>
                    <AppLogo src={logo} alt="React Logo" />
                    <AppTitle>
                    Coin Exchange
                    </AppTitle>
                </AppHeader>
            )
        }
    }




CoinList.jsx

import React, { Component } from 'react';
import Coin from '../Coin/Coin';
import styled from 'styled-components';

const CoinTable = styled.table`
  margin: 50px auto 50px auto;
  display: inline-block;
  font-size: 1.4rem;
`

export default class CoinList extends Component {
    render() {
        return (
                <CoinTable>
                <thead>
                    <tr>
                    <th>Name</th>
                    <th>Ticker</th>
                    <th>Price</th>
                    </tr>
                </thead>
                <tbody>
                    {
                    this.props.coinData.map(value => <Coin key = {value.ticker} name = {value.name} ticker = {value.ticker} price = {value.price}/>)
                    }
                </tbody>
                </CoinTable>
        )
    }
}

Coin.jsx

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';

const Td = styled.td`
border: 1px solid #cccccc;
width: 25vh;
`;

const Button = styled.button`
  background: transparent;
  border-radius: 3px;
  border: 2px solid palevioletred;
  color: palevioletred;
  margin: 0 1em;
  padding: 0.25em 1em;
`;

export default class Coin extends Component {
    constructor(props) {
        super(props);
        this.state = {
            price: this.props.price
        };
        this.handleClick = this.handleClick.bind(this);
    }

    /*
    componentDidMount() {
        const callback = () => {
            // set the state to a new random variable
            const randomPercentage = 0.995 + Math.random() * 0.01;

            this.setState( function(oldState) {
                return {
                    price: (oldState.price * randomPercentage)
                };
            });
        }
        setInterval(callback, 5000);
    }
    */


    handleClick(event) {
        // We have to prevent the default action from submitting the form
        event.preventDefault();

        const randomPercentage = 0.995 + Math.random() * 0.01;
        this.setState( function(oldState) {
            return {
                price: (oldState.price * randomPercentage)
            };
        });
    }

    render() {
        return (
            <tr>
                <Td>{this.props.name}</Td>
                <Td>{this.props.ticker}</Td>
                <Td>${this.state.price}</Td>
                <td><Button onClick = {this.handleClick}>Refresh</Button></td>
            </tr>
        );
    }
}

Coin.propTypes = {
    name: PropTypes.string.isRequired,
    ticker: PropTypes.string.isRequired,
    price: PropTypes.number.isRequired
}
1 Like

omg, should’ve just watched the solution video before asking help here haha.
Was just determined to sort it without the solution :eyes:

For anyone else with the same problem, you should move the logo svg into the ExchangeHeader folder with git, using the command from in the coin-exchange/src folder:

git mv ./logo.svg ./components/ExchangeHeader/logo.svg

And then use the regular import logo from './logo.svg' at the start of the ExchangeHeader.jsx file, and the <AppLogo src={logo} alt="React Logo"/> in the header. :partying_face:

1 Like

App.js becomes:

import React from 'react';
import './App.css';
import AppHeader from './components/AppHeader/AppHeader';
import CoinList from './components/CoinList/CoinList';
import AccountBalance from './components/AccountBalance/AccountBalance';

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      balance: 1000,
      coinData: [
        { name:"Bitcoin",  ticker:"BTC",  price:35000.90 },
        { name:"Ethereum", ticker:"ETH",  price:2123.55 },
        { name:"Tether",   ticker:"USDT", price:1.0 },
        { name:"Ripple",   ticker:"XRP",  price:0.2 },
        { name:"Bitcoin Cash", ticker:"BCH",  price:399.99 },
      ]
    }
  }

  render() {
    return (
      <div className="App">
        <AppHeader />
        <AccountBalance amount={this.state.balance} />
        <CoinList coinData={this.state.coinData} />
      </div>
    );
  }
}

export default App;

The new components/AppHeader/AppHeader.jsx is:

import React, { Component } from 'react';
import logo from './logo.svg';
import styled from 'styled-components';

const Header = styled.header`
    background-color: #282c34;
    min-height: 20vh;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    color: white;
`;

const Img = styled.img`
    height: 8rem;
    pointer-events: none;
`;

const H1 = styled.h1`
    font-size: 4rem;
`;

export default class AppHeader extends Component {
  render() {
    return (
      <>
        <Header>
          <Img src={logo} alt="React logo" />
          <H1>Coin Exchange</H1>
        </Header>
      </>
    )
  }
}

logo.svg file is moved to AppHeader folder too

1 Like