This is not related to React. However, you can use the download
attribute on the anchor <a>
element to tell the browser to download the file.
<a href="https://stackoverflow.com/somefile.txt" download>Click to download</a>
This is not supported on all browsers: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a
More Related Contents:
- “SyntaxError: Unexpected token < in JSON at position 0"
- ReactJS – Does render get called any time “setState” is called?
- React onClick function fires on render
- React Js conditionally applying class attributes
- React – User-Defined JSX Components Not rendering
- ReactJS – Lifting state up vs keeping a local state
- TypeError: _firebase__WEBPACK_IMPORTED_MODULE_2__.default.collection is not a function
- How to fix error “Failed to compile : ./node_modules/@react-leaflet/core/esm/path.js 10:41 Module parse failed: Unexpected token (10:41)”
- How to pass in a react component into another react component to transclude the first component’s content?
- Uncaught TypeError: Cannot read property ‘push’ of undefined (React-Router-Dom)
- Github – unexpected disconnect while reading sideband packet
- Is it possible to initiate a download prompt in the browser for recognized MIME types using only JavaScript (client-side approach)?
- How do you pass data when using the navigate function in react router v6
- How do I access store state in React Redux?
- Read Store’s Initial State in Redux Reducer
- How to pass state back to parent in React?
- In React.js should I make my initial network request in componentWillMount or componentDidMount?
- Is componentDidMount of parent called after all componentDidMount of children?
- Error “Error: A is only ever to be used as the child of element”
- ReactJS – Get Height of an element
- How to get selected value of a dropdown menu in ReactJS
- Retrieving value from with multiple option in React
- Images not loading when relative path is used in React
- Pros/cons of using redux-saga with ES6 generators vs redux-thunk with ES2017 async/await
- Can’t call setState on a component that is not yet mounted
- React-Redux: Should all component states be kept in Redux Store
- React.js best practice regarding listening to window events from components
- React’s setState method with prevState argument
- How to render a Object in React?
- How to fetch data server-side in the app directory of Next.js? Tried getStaticProps but it’s returning undefined