score:0
it seems to me that the component is a bit too involved with the refresh mechanism, so i'd delegate that to a redux action instead:
// async download action
const downloadfile = (filename) => async (dispatch, getstate) => {
await dispatch(refresh());
const file = getstate().all.files[filename];
file.download(); // it's not recommended to have functions in redux state btw
};
function downloadbutton(props) {
const { selected, downloadfile } = props;
return(
<>
{!!selected && <downloadbutton onclick={() => downloadfile(selected)} />}
</>
);
}
const mapdispatchtoprops = { downloadfile };
Source: stackoverflow.com
Related Query
- Ensure redux state is current across browser sessions
- How can I access current redux state from useEffect?
- Content doesn't change when back/forward made on browser with state data in React + Redux
- How to Jump to Redux State with Browser Back Button
- Is there a way to view state changes across page reloads in the State tab in Redux DevTools?
- Browser back button to reverse to previous redux state
- How to access current store state in redux outside of react?
- How to access current Redux state with Reselect?
- Redux pass up/refresh state from current page
- How to access current state on Redux Toolkit on createAsyncThunk
- Redux Toolkit createEntityAdapter: how can i get current state of adapter?
- Redux state is not uniform across all tabs
- Redux adding nested value to current state
- Redux how to check if user is logged in inside auth reducer state parameter using sessions
- React redux doesn't return current state value
- How to disable redux devtool to hide state in browser after production?
- Redux State Not Updated In Dev Tools But Current State Is Being Reflected In Props
- Redux State Does Not Get Updated In Dev Tools But Current State Is Being Reflected In Props
- Functional component breaks on browser refresh because object that is pulled from redux state isn‘t available on time
- How can I persist redux state tree on refresh?
- While debugging, can I have access to the Redux store from the browser console?
- How to access state inside Redux reducer?
- Read Store's Initial State in Redux Reducer
- How to sync Redux state and url hash tag params
- I am using Redux. Should I manage controlled input state in the Redux store or use setState at the component level?
- how to set initial state in redux
- React + Redux - Input onChange is very slow when typing in when the input have a value from the state
- When do I choose React state Vs Redux Store
- My Redux state has changed, why doesn't React trigger a re-render?
- Redux state is undefined in mapStateToProps
More Query from same tag
- React inline logic in render()
- Change a single parameter in URL
- Render object in React
- How to create an animated counter in React.js?
- onclick event for Imported component in react?
- How to pass props to styled component when using theme?
- How to sort firebase document by date in React?
- How do I resolve unmounted component error
- Passing a variable from a jade file to a React Component
- How can draw tick related style like major tick, tick-length, position, color in react-google-charts
- export or send data in react
- checkBox once at the time in React
- onChange event handler function attached with input field to update the state of the app executes once on first load and twice afterwords
- How to define a literal object to store different properties with generics
- Why isn't my React Hook updating when I setState?
- React generate <option> tags for a <select> element before render
- Making TodoList in React, how to cross out item when finished (not using index)?
- How to display Google Locations reviews on my website with google api?
- Rails + React.js : Hiding information from view
- Why is the assigned object not being written too?
- [React/JSX]: Remove CSS classes on sibling components, when the current component is clicked
- React Apollo Query keeps making network requests indefinitely with pollInterval
- Go back 2 pages - React-Router - ReactJS -
- Convert JSON data to table
- how to get axios.get data and where to put it in redux reducer initial state
- How to source images from a YAML array in Gatsby.js
- React - Babel not transpiling files
- how to replace all the periods after the first of a string with the javascript replace function?
- Css is not rendering when i move from Login page to registration page in Routing
- Material-ui AppBar. Changing color on scroll. React