Comments (6)
有一点讨论一下下,我建议使用 getModalProps
和 getFormProps
函数去获取对应的 props,因为函数会更加灵活,可以加入自定义处理逻辑,比如 getFormProps(props)
,根据不同的 props
可能会有不同的返回。
from sunflower.
没有太明白需求呢?要是想用 props 可:
import { Modal, Form } from 'antd';
import { useModalForm } from 'sunflower-antd';
function Component(props) {
const { modalProps, formProps, show, close, visible } = useModal({
defaultVisible: false,
autoSubmitClose: true,
async submit() {},
})
return <>
<Modal okText="submit" {...modalProps} {...props}>
<Form {...formProps} />
</Modal>
modal visible: {visible}
<a onClick={() => show()}>show modal</a>
<a onClick={() => close()}>close modal</a>
</>
}
export default Component;
from sunflower.
我是有遇到过一个问题,如下所示,
function App(props) {
const { modalProps, formProps, show, close, visible } = useModal({})
return <>
<Modal okText="submit" onOk={props.onOk} {...modalProps} >
<Form {...formProps} />
</Modal>
</>
}
如果,modalProps
也包含 onOk
事件处理器,那么 modalProps
会覆盖掉你的自定义的 onOk
事件处理器,就算把 modalProps
放到 onOk
前面,也会相互覆盖。如果我们是用 getModalProps
去获取 Modal
相关的 props
,那么我们可以这样做,
getModalProps: props => ({
...,
onOk: args => [props.onOk, this.onOk].forEach(fn => fn && fn(...args))
})
from sunflower.
看看是否这样就行:
function App(props) {
const { modalProps, formProps, show, close, visible } = useModal({})
return <>
<Modal okText="submit" {...modalProps} onOk={() => {
props.onOk();
modalProps.onOk();
}}>
<Form {...formProps} />
</Modal>
</>
}
from sunflower.
useModalForm 是否要再传一个onOK函数 支持用户点击提交时做一些额外操作
function App(props) {
const { modalProps, formProps, show, close, visible } = useModalForm({
onOK: props.onOk,
})
return <>
<Modal okText="submit" {...modalProps} >
<Form {...formProps} />
</Modal>
</>
}
from sunflower.
from sunflower.
Related Issues (20)
- [Error on Development] Can't find module
- Go to previous step without checking validation HOT 1
- useStepFrom Steps onChange bug HOT 2
- Does it also work with AntDesign 5?
- useStepsForm does not preserve form field values when returning to Previous step
- useFormTable spec HOT 1
- doc
- DOC
- useModal spec HOT 2
- useFormtable add reset方法
- useStepsForm spec HOT 1
- useForm spec
- useFormTable 如何在用编程的方式触发刷新 HOT 3
- useFormTable 和 useModalForm 怎么同时使用 antd@3 HOT 3
- typescript下useFormTable返回的tableProps和antd的Table类型不匹配 HOT 1
- [Bug] useStepsForm should prevent form submitting when the form is invalid HOT 2
- remove monorepo
- i18n doc and 1.0
- will upgrade to antd 4.0? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sunflower.