diff --git a/16_Higher_Order_Component/16_higher_order_component_boilerplate/src/index.js b/16_Higher_Order_Component/16_higher_order_component_boilerplate/src/index.js index 63d00cd..2815098 100644 --- a/16_Higher_Order_Component/16_higher_order_component_boilerplate/src/index.js +++ b/16_Higher_Order_Component/16_higher_order_component_boilerplate/src/index.js @@ -1,133 +1,95 @@ import React, { Component } from 'react' -import axios from '../../../17_React_Router/15_react_router_boilerplate/src/node_modules/axios' import ReactDOM from 'react-dom' -import moment from '../../../17_React_Router/15_react_router_boilerplate/src/node_modules/moment' -import styled from 'styled-components' -import { - TiSocialLinkedinCircular, - TiSocialGithubCircular, - TiSocialTwitterCircular, -} from '../../../17_React_Router/15_react_router_boilerplate/src/node_modules/react-icons/ti' -const Title = styled.h1` - font-size: 70px; - font-weight: 300; -` -const SubTitle = styled.h2` - font-weight: 300; -` - -const Header = styled.header` - background-color: #61dbfb; - padding: 25; - padding: 10px; - margin: 0; -` - -class App extends Component { - constructor(props) { - super(props) - console.log('I am the constructor and I will be the first to run.') - this.state = { - firstName: 'John', - data: [], - day: 1, - congratulate: '', - } - } +const Button = ({ onClick, text, style }) => { + return ( + + ) +} - componentDidMount() { - const API_URL = 'https://restcountries.eu/rest/v2/all' - axios - .get(API_URL) - .then((response) => { - this.setState({ - data: response.data, - }) - }) - .catch((error) => { - console.log(error) - }) +const buttonWithStyles = (CompParam, bgColor = 'default') => { + const colors = [ + { + name: 'default', + backgroundColor: '#e7e7e7', + color: '#000000', + }, + { + name: 'react', + backgroundColor: '#61dbfb', + color: '#ffffff', + }, + { + name: 'success', + backgroundColor: '#4CAF50', + color: '#ffffff', + }, + { + name: 'info', + backgroundColor: '#2196F3', + color: '#ffffff', + }, + { + name: 'warning', + backgroundColor: '#ff9800', + color: '#ffffff', + }, + { + name: 'danger', + backgroundColor: '#f44336', + color: '#ffffff', + }, + ] + const { backgroundColor, color } = colors.find((c) => c.name === bgColor) + const buttonStyles = { + backgroundColor, + padding: '10px 45px', + border: 'none', + borderRadius: 3, + margin: 3, + cursor: 'pointer', + fontSize: '1.25rem', + color, } - static getDerivedStateFromProps(props, state) { - return { firstName: props.firstName } - } - shouldComponentUpdate(nextProps, nextState) { - console.log(nextProps, nextState) - console.log(nextState.day) - if (nextState.day > 31) { - return false - } else { - return true - } + return (props) => { + return } +} - doChallenge = () => { - this.setState({ - day: this.state.day + 1, - }) - } - renderCountries = () => { - return this.state.data.map((country) => { - const languageOrLanguages = - country.languages.length > 1 ? 'Langauges' : 'Language' - const formatLanguages = country.languages - .map(({ name }) => name) - .join(', ') - return ( -
-
- {' '} - {country.name}{' '} -
-
-

{country.name}

-

Capital: {country.capital}

-

- {languageOrLanguages}: {formatLanguages} -

-

Population: {country.population}

-
-
- ) - }) - } - componentDidUpdate(prevProps, prevState) { - if (prevState.day == 30) { - this.setState({ - congratulate: 'Congratulations,Challenge has been completed', - }) - } - console.log(prevState, prevProps) - } +const NewButton = buttonWithStyles(Button) +const ReactButton = buttonWithStyles(Button, 'react') +const InfoButton = buttonWithStyles(Button, 'info') +const WarningButton = buttonWithStyles(Button, 'warning') +const DangerButton = buttonWithStyles(Button, 'danger') +const SuccessButton = buttonWithStyles(Button, 'success') +class App extends Component { render() { return (
-
- 30 Days Of React -

Getting Started React

-

JavaScript Library

-

Instructor: Asabeneh Yetayey

- Oct 15, 2020 -
-

This challenge was started {moment('2020-10-01').fromNow()}

-

The challenge will be over in {moment('2020-10-30').fromNow()}

-

Today is {moment(new Date()).format('MMMM DD, YYYY HH:mm')}

-

React Component Life Cycle

-

Calling API

- - - - - -

Challenge: Day {this.state.day}

- {this.state.congratulate &&

{this.state.congratulate}

} -
-

There are {this.state.data.length} countries in the api

-
{this.renderCountries()}
-
+

Higher Order Components

+
) }