Giter Site home page Giter Site logo

useModelForm spec about sunflower HOT 6 CLOSED

ant-design avatar ant-design commented on August 20, 2024
useModelForm spec

from sunflower.

Comments (6)

starandtina avatar starandtina commented on August 20, 2024

有一点讨论一下下,我建议使用 getModalPropsgetFormProps 函数去获取对应的 props,因为函数会更加灵活,可以加入自定义处理逻辑,比如 getFormProps(props),根据不同的 props 可能会有不同的返回。

from sunflower.

JIACHENG9 avatar JIACHENG9 commented on August 20, 2024

没有太明白需求呢?要是想用 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.

starandtina avatar starandtina commented on August 20, 2024

我是有遇到过一个问题,如下所示,

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.

JIACHENG9 avatar JIACHENG9 commented on August 20, 2024

看看是否这样就行:

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.

Mr-zyy avatar Mr-zyy commented on August 20, 2024

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.

JIACHENG9 avatar JIACHENG9 commented on August 20, 2024

#56

from sunflower.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.