admin管理员组文章数量:1355542
I'm using react query.
There is an array of documents (just describing data, no real blobs) with an option to download. They have an onClick handler which calls a function which handles the download.
And in case the user clicks on the download button there is a http request getDocumentById to get the document you want to download.
The Problem is, I can not call my custom query hook in that handleDownload function. But the only place I have my specific document Id is in that function.
const parseDocuments = () => {
return documents.map(document => ({
...document,
name: document.fileName,
date: formatDateForUI(new Date(document.created)),
downloadDocumentHandler: () => downloadFileClickHandler(document),
read: document.read
}));
}
function handleDownload(document) {
<here I need to call the getDocumentById>
}
return (
<DocumentsTable documents={parseDocuments()} headers={headers} accountId={accountId} />
)
How is the best way to handle this?
I'm using react query.
There is an array of documents (just describing data, no real blobs) with an option to download. They have an onClick handler which calls a function which handles the download.
And in case the user clicks on the download button there is a http request getDocumentById to get the document you want to download.
The Problem is, I can not call my custom query hook in that handleDownload function. But the only place I have my specific document Id is in that function.
const parseDocuments = () => {
return documents.map(document => ({
...document,
name: document.fileName,
date: formatDateForUI(new Date(document.created)),
downloadDocumentHandler: () => downloadFileClickHandler(document),
read: document.read
}));
}
function handleDownload(document) {
<here I need to call the getDocumentById>
}
return (
<DocumentsTable documents={parseDocuments()} headers={headers} accountId={accountId} />
)
How is the best way to handle this?
Share Improve this question edited Mar 31, 2021 at 16:32 Jason Aller 3,65228 gold badges41 silver badges39 bronze badges asked Mar 31, 2021 at 15:45 btrautmannbtrautmann 432 silver badges5 bronze badges1 Answer
Reset to default 8I've got a problem I don't know the answer.
Then you've e to the right place.
I'm using react query.
That is very good
本文标签: javascriptuseQuery call in onClickHandler with object of arrayStack Overflow
版权声明:本文标题:javascript - useQuery call in onClickHandler with object of array - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744010526a2575477.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论