I’ve solved my problem.
handleClick = () => {
fetch('/sample.txt')
.then((r) => r.text())
.then(text => {
console.log(text);
})
}
Tis link did help:
Fetch local JSON file from public folder ReactJS
More Related Contents:
- How to push to History in React Router v4?
- How to display svg icons(.svg files) in UI using React Component?
- How to use callback with useState hook in react [duplicate]
- Why do the React docs recommend doing AJAX in componentDidMount, not componentWillMount?
- How to use throttle or debounce with React Hook?
- Why, exactly, do we need React.forwardRef?
- You should not use outside a
- Axios having CORS issue
- react router v4 default page(not found page)
- Use Connect or pass data as props to children
- react.js custom events for communicating with parent nodes
- IMAGE: You may need an appropriate loader to handle this file type
- Nested Routes not rendering with React Router v4
- Visual studio code changes format (React-JSX)
- Error while creating new React app (“You are running `create-react-app` 4.0.3, which is behind the latest release (5.0.0)”)
- Re-initializing class on redirect
- React – TypeError: Cannot read properties of undefined (reading ‘params’)
- React Hook “useState” is called in function “app” which is neither a React function component or a custom React Hook function
- React router, pass data when navigating programmatically?
- React: Why component’s constructor is called only once?
- Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema
- Relative path in index.html after build
- Callback when DOM is loaded in react.js
- Jest test fails : TypeError: window.matchMedia is not a function
- Typescript React: Access component property types
- React and TypeScript—which types for an Axios response?
- You cannot render a inside another . You should never have more than one in your app
- React – Is useState ‘s setter function able to change?
- Is it possible to return empty in react render function?
- How to remove the hash from the url in react-router