Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

350
Views
How to read local text file in reactjs?

I am creating a react website by create-react-app. I have some markdown files in current directory. I want to preview them in the website (like github shows markdown files in preview format). I've found markdown previewer ReactMarkdown. Now the only code I need is a React functional/class component that will read markdown files. I've tried some solutions in stackoverflow but none of them worked.

This is my App.js

import ReactMarkdown from 'react-markdown';
import ReadFileData from './ReadFileData';
import data from './file.md'; 
// const data = require('./file.md');
import './App.css';

function App() {
  return (
    <div className="App">
      <ReactMarkdown><ReadFileData data={data}/></ReactMarkdown>
    </div>
  );
}

export default App;

I've wrote a small part of ReadFileData.js. But I don't know how to complete it.

import React from "react";

class ReadFileData extends React.Component {

  render(){

    const unparsed = this.props.data;

    console.log(unparsed);

//  The code I need

    const readAbleData = "unknown";

    return(
        <div>
            <p>{readAbleData}</p>
        </div>
    );
  }
}

export default ReadFileData;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can read it with fetch:

const myMarkdownFile = require("./file.md");

fetch(myMarkdownFile)
  .then(response => response.text())
  .then(text => this.setState({ text }))
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!