Skip to content

Instantly share code, notes, and snippets.

@kianaditya
Created September 4, 2020 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kianaditya/0f0d7b045b63b635d4e43faec3fa06ef to your computer and use it in GitHub Desktop.
Save kianaditya/0f0d7b045b63b635d4e43faec3fa06ef to your computer and use it in GitHub Desktop.
cypress toggle mocked routes
import React, { useState, useEffect } from 'react'
import Axios from 'axios'
const URL = 'https://jsonplaceholder.typicode.com/todos'
const App = () => {
const [todos, setTodos] = useState([])
useEffect(() => {
fetchTodos()
}, [])
const fetchTodos = async () => {
const response = await Axios.get(URL)
setTodos(response.data)
}
return (
<div>
{todos.map((todo) => {
return (
<div key={todo.id}>
<h3>{todo.title}</h3>
</div>
)
})}
</div>
)
}
export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment