create FileName.txt in public folder
and run localhost:3000/FileName.txt
| Anmol Kumar Singh |
| import React, { Component } from 'react'; | |
| import MyText from './FileName.txt'; | |
| class RenderText extends Component { | |
| componentDidMount = () => { | |
| this.handleClick(); | |
| }; | |
| handleClick = () => { | |
| fetch(MyText) | |
| .then((r) => r.text()) | |
| .then((text) => { | |
| console.log(text); | |
| this.setState({ text }); | |
| }); | |
| }; | |
| render() { | |
| return ( | |
| <div> | |
| <p>{this.state?.text}</p> | |
| </div> | |
| ); | |
| } | |
| } | |
| export default RenderText; |
make public