Skip to content
Advertisement

How to read Github’s files(specially Markdown files) in React Project?

I want to read or embed Markdown files in my React Project? I just try following the code.

This Import Section:

JavaScript

Then Here Constant and State:

JavaScript

Then I am using UseEffect to initial render and get the file from GitHub:

useEffect( () => {

JavaScript

then Here html section:

JavaScript

But I have error in Console: 404 code error! How could I read the file from Github? Please Help me.

Advertisement

Answer

  1. Make sure you fetch the markdown as raw data and not just from the page. You can do this by clicking the Raw button in the top left on the file’s page.
  2. It seems you imported axios but then just used fetch. Make sure to decide on just one of them.

Here is a CodeSandbox the proposed changes.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement