This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import useEffect from 'react' | |
| useEffect(() => { | |
| // declare the data fetching function | |
| const fetchmyTarot = async() => { | |
| // get data from the api | |
| const response = await fetch("https://rws-cards-api.herokuapp.com/api/v1/cards/random?n=10") | |
| // handle response error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function App() { | |
| const [play,setPlay] = useState([]) | |
| const [error,setError] = useState({}) | |
| useEffect(() => { | |
| .fetch('https://jsonplaceholder.typicode.com/todos') | |
| .then(response => response.json()) | |
| .catch(err => setError(err)) | |
| },[]) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react'; | |
| class StateExample extends Component { | |
| constructor(){ | |
| super(); | |
| this.state = { | |
| car_brand: 'Volvo', | |
| car_color: 'bluesky' | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| function Example(props) { | |
| return ( | |
| <div> | |
| <h1>Class Comonent</h1> | |
| <p>{this.state.car_brand}</p> | |
| <p>{this.state.car_colord}</p> | |
| </div> | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useState, useEffect } from "react"; | |
| const TodoList = () => { | |
| const [todos, setTodos] = useState(); | |
| useEffect(() => { | |
| axios.get(`https://jsonplaceholder.typicode.com/posts`) | |
| .then((response) => { | |
| const responseTodos = response.data; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default function Home({posts}) { | |
| <div> | |
| {posts.map(post => ( | |
| <div key={post.id}> | |
| <h1>{post.title}</h1> | |
| <p>{post.id}</p> | |
| </div> | |
| ))} | |
| </div> |