Javascript React Js调用另一个传递道具的函数
我不熟悉react js和redux。在这里,我对两个不同的地方使用相同的组件,并作为道具传递一些函数 这是我的常用组件,其中我有一个名为TestComp的组件,它接受一些道具,一个是函数handleChangeJavascript React Js调用另一个传递道具的函数,javascript,reactjs,Javascript,Reactjs,我不熟悉react js和redux。在这里,我对两个不同的地方使用相同的组件,并作为道具传递一些函数 这是我的常用组件,其中我有一个名为TestComp的组件,它接受一些道具,一个是函数handleChange <SelectFileButton accept='application/pdf' handleSubmit={file => handleSubmit(file, 'test')} /> handleSubmit(文件'test')} /> 现
<SelectFileButton
accept='application/pdf'
handleSubmit={file => handleSubmit(file, 'test')}
/>
handleSubmit(文件'test')}
/>
现在,这个组件实现了handleChanges方法。现在,
从另一个地方我使用相同的组件
<TestDocument
handleSubmit={file => actionFunction(URL,file)}
/>
actionFunction(URL,文件)}
/>
现在这个组件有了自己的handleSubmit函数的实现。这是在同一个组件中
<TestDocument
handleSubmit={file => actionFunction(URL,file)}
/>
现在,我正在尝试的是,在将道具传递给函数的同时,我正在调用其中的另一个函数,这也不会破坏另一个组件的实现
所以,我尝试的是传递另一个函数作为道具
const actionFunction = (URL,file) => {
this.handleSubmit()
}
<TestDocument
handleSubmit={file => actionFunction(URL,file)}
/>
const actionFunction=(URL,文件)=>{
this.handleSubmit()
}
actionFunction(URL,文件)}
/>
那么,我能做些什么来使用这个吗?如果我理解正确的话。你需要试试这个
export default function TestDocument (props) {
return (
<form handleSubmit={file => props.handleSubmit(URL,file)}>
...
</form>
);
}
导出默认函数TestDocument(props){
返回(
props.handleSubmit(URL,文件)}>
...
);
}
呈现测试文档:
<TestDocument handleSubmit={this.handleSubmit}/>
如果我理解正确的话。你需要试试这个
export default function TestDocument (props) {
return (
<form handleSubmit={file => props.handleSubmit(URL,file)}>
...
</form>
);
}
导出默认函数TestDocument(props){
返回(
props.handleSubmit(URL,文件)}>
...
);
}
呈现测试文档:
<TestDocument handleSubmit={this.handleSubmit}/>