Giter Site home page Giter Site logo

Comments (6)

bowencool avatar bowencool commented on June 12, 2024

发布的时候 antd 还没发布 v5 ... 这两天看一下

from create-antd-modal.

pangxzi avatar pangxzi commented on June 12, 2024

发布的时候 antd 还没发布 v5 ... 这两天看一下

👌

from create-antd-modal.

bowencool avatar bowencool commented on June 12, 2024

这个是因为 modal 是动态创建的,不在页面的组件树上,所以获取不到各种 context 的值。
官方利用 useModal 返回 holder 是一种很好的解决办法,就是不够简洁。我尽量想想成本更低的方法

from create-antd-modal.

pangxzi avatar pangxzi commented on June 12, 2024

这个是因为 modal 是动态创建的,不在页面的组件树上,所以获取不到各种 context 的值。 官方利用 useModal 返回 holder 是一种很好的解决办法,就是不够简洁。我尽量想想成本更低的方法

from create-antd-modal.

bowencool avatar bowencool commented on June 12, 2024

抱歉这么晚解决,现在你可以使用 createFunctionWithDefaultProps 了,详情查看文档

from create-antd-modal.

bowencool avatar bowencool commented on June 12, 2024

v1.5.0 增加了 useModalCreation,使用更便捷

import React from 'react';
import { Button } from 'antd';
import { useModalCreation } from 'create-antd-modal';
import RootContainer from './RootContainer';

const Demo: React.FC = () => {
  const [contextHolder, createModal] = useModalCreation();
  return (
    <RootContainer>
      <Button
        onClick={() => {
          createModal({
            title: 'Some title',
            content: 'You can see that the i18n and theme configuration works now',
          });
        }}
      >
        Context Providing
      </Button>
      {contextHolder}
    </RootContainer>
  );
};

export default Demo;

from create-antd-modal.

Related Issues (1)

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.