score:2
look at this code it will help to tweak your code
export default function datalistpage(props: datalistprops) {
const csvlinkref = useref<
csvlink & htmlanchorelement & { link: htmlanchorelement }
>(null); // setup the ref that we'll use for the hidden csvlink click once we've updated the data
const [data, setdata] = usestate<datatypeobj[]>([]);
const hanldeexportbutton = async () => {
const data: datatypeobj[] = await fetchdata();
setdata(data);
csvlinkref?.current?.link.click();
};
return (
<csvlink
data={data}
classname="exportbutton"
filename="file.csv"
ref={csvlinkref}
>
</csvlink>
<button
color="primary"
variant="contained"
size="small"
starticon={<getappicon />}
onclick={hanldeexportbutton}
>
export as csv
</button>
);
} //func datalistpage end
Source: stackoverflow.com
Related Query
- How to add ref to CSVLINK in react typescript?
- React Typescript - How add Types to location.state when passed in a Route
- How to add react with typescript to existing asp.net core mvc application
- How do I add type to onChange & onClick functions in typescript react
- How do I fix a React TypeScript error with the return value of useHotkeys hook not matching the type of the div element ref prop
- How to add event listener to the div element accessed with ref using react and typescript?
- How to add a function in an interface React Typescript
- How can I add onClick event for Ref Element using React Hooks?
- I can't figure out how to add Typescript to my React useState hooks, what am I doing wrong?
- React TypeScript 16.8 How to add a dependency to useEffect()
- How to add ref for react element (node reactNode!)
- How to add item in redux with dictionary type in react typescript
- How to add CSS new 'content-visibility' property to a React class component that uses Typescript and SCSS?
- React Typescript How to add a new array to an array of objects useState
- How to Add route links to material ui tabs in react typescript
- Typescript - How to add type definition to React classical component
- How to add another table row on click in react app using typescript
- How to add TypeScript 3.7 Optional Chaining support to create react app project
- how to declare a react ref in props function when using typescript
- How to extend a ref type for forwardRef in react and typescript to allow multiple refs
- How to add ref to a react styled component div using react and typescript?
- How do I conditionally add attributes to React components?
- How to use refs in React with Typescript
- How to specify (optional) default props with TypeScript for stateless, functional React components?
- How to define css variables in style attribute in React and typescript
- How do I add validation to the form in my React component?
- How do I restrict the type of React Children in TypeScript, using the newly added support in TypeScript 2.3?
- How do I use external script that I add to react JS?
- How to add SCSS styles to a React project?
- React TypeScript 16.8 How to make useEffect() async
More Query from same tag
- Smooth wrapper background-image transition, when using React onMouseEnter and onMouseLeave events on a childs
- React + Styled Components: Am I supposed to avoid CSS files altogether?
- Scrolling div ticker
- How can i add style to the root of React's CreatableSelect?
- Overlap Button on Buttons using Styled Components
- HighCharts not updating when the state changes in React
- Typing a function that can accept/return N array of items with rest/spread generics?
- Component does not render on button click
- Component library that's depending on a third part library or framework
- How to unit test a component under React Router 4
- Attribute is not saved in Gutenberg
- How to pass a value from a custom dropdown component to react-hook-form?
- store data in browser
- I have a component which is receiving data from the store. How can I update the data received and rerender the component on change
- Passing HTML element as a prop with other props
- Using Playfab SDK with ReactJS?
- is it possible to display number of week in row with selected week?
- Finding mouse target in react
- How to implement Theme Switcher From a React Component
- How can a function value is displayed in a HTML tag with a return value from addEventListerner click?
- Partial function input in TypeScript
- display an array which is a result of useCollectionData in react
- React 0.13 get data from REST endpoint
- I need to pull data from another Firestore collection based on forEach data within a onSnapshot call
- eslint error on deployment on local server of react web app
- Order data in localStorage
- Objects are not valid as a React child (found: TypeError: NetworkError when attempting to fetch resource.)
- ReactJS - How can I implement pagination for react with keep state when route change?
- How to return first_name already exist when he submit with the same first_name in database
- When to use a react framework such as Next or Gatsby vs Create React App