[英]React Js Calling another function passing the props
我是 react js 和 redux 的新手。 在這里,我在兩個不同的地方使用相同的組件,並將一些函數作為道具傳遞。
這是我的通用組件,其中我有以下組件,其名稱為 TestComp,並且接受一些道具,其中一個是函數 handleChange。
<SelectFileButton
accept='application/pdf'
handleSubmit={file => handleSubmit(file, 'test')}
/>
現在,該組件具有 handleChanges 方法的實現。 現在,我從另一個地方使用相同的組件。
<TestDocument
handleSubmit={file => actionFunction(URL,file)}
/>
現在這個組件有它自己的 handleSubmit 函數的實現。 那是在同一個組件中。
現在,我正在嘗試的是在將道具傳遞給函數時,我正在調用其中的另一個函數,該函數也不會破壞另一個組件的實現。
所以,我嘗試的是將另一個函數作為道具傳遞。
const actionFunction = (URL,file) => {
this.handleSubmit()
}
<TestDocument
handleSubmit={file => actionFunction(URL,file)}
/>
那么,我可以做些什么來使用它嗎?
如果我理解正確的話。 你需要試試這個
export default function TestDocument (props) {
return (
<form handleSubmit={file => props.handleSubmit(URL,file)}>
...
</form>
);
}
渲染測試文檔:
<TestDocument handleSubmit={this.handleSubmit}/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.