NextJs / Web / Step4: Api data
Step4 : API integration
-
STEPS
1. define state
state = { todos: [] } 2. appi call using axios and set state
Complete codeaxios .get("https://jsonplaceholder.typicode.com/todos?_page=1&_limit=10") .then(response => { this.setState({ todos: response.data }); }) .catch(function(error) { console.log(error); }); -
POST METHOD
export default class PersonAdd extends React.Component { state = { name: '' } handleChange = event => { this.setState({ name: event.target.value }); } handleSubmit = event => { event.preventDefault(); const user = { name: this.state.name }; axios.post(`https://jsonplaceholder.typicode.com/users`, { user }) .then(res => { console.log(res); console.log(res.data); }) } render() { return (