Skip to content
Discussion options

You must be logged in to vote

Hi @JuzouSatoru2

In order to do this, you'd need to do something like this instead:

import React from 'react';
import axios from 'axios';
import { useRouter } from 'next/router'
import Layout from '../../../components/Layout';

function Edit() {
  const [post, setPost] = React.useState(null);

  const router = useRouter();
  const { slug } = router.query;

  // useEffect will run on each render only if the `slug` changes,
  // so on initial render once `useRouter` has the query then it'll run the effect
  React.useEffect(() => {
    // fetchData runs async, so whenever the response comes back
    // then you can set some state, in this case `setPost(data)`
    const fetchData = async () => {

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@alex289
Comment options

Answer selected by alex289
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #13729 on June 03, 2020 19:21.