Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NiceModalProps should let objects with id #106

Closed
osrl opened this issue Mar 13, 2023 · 5 comments
Closed

NiceModalProps should let objects with id #106

osrl opened this issue Mar 13, 2023 · 5 comments

Comments

@osrl
Copy link

osrl commented Mar 13, 2023

NiceModalHocProps has a field named id. This is too common and prevents us to pass a type with id in it.

This is not possible:

NiceModal.create(
  (object: { id: string; foo: string }) => { ... }

I actually opened a PR for this #96. But closed it since it wasn't backward compatible.

To reproduce:

export const FoodModal = NiceModal.create(
  (arg: { id: string }) => {

    return (
      <div></div>
    );
  }
);


NiceModal.show(FoodModal, {id: "foo"}) // No overload matches this call
export const FoodModal = NiceModal.create(
  (arg: { fooId: string }) => {

    return (
      <div></div>
    );
  }
);


NiceModal.show(FoodModal, {fooId: "foo"}) // It's okay now
@supnate
Copy link
Collaborator

supnate commented Mar 13, 2023

hmm, I remember calling modal.show(modal, args) can use any prop name.

@supnate
Copy link
Collaborator

supnate commented Mar 14, 2023

Just tried and it works but with typescript error.
Need to fix the type check of modal.show().

export const MyAntdModal = NiceModal.create(({ name , id}: { name: string, id: string }) => {
  const modal = useModal();
  return (
    <Modal title="Hello Antd" visible={modal.visible} onOk={modal.hide} onCancel={modal.hide} afterClose={modal.remove}>
      Greetings: {name} ({id})!
    </Modal>
  );
});

export default function AntdSample() {
  return (
    <Space>
      <Button type="primary" onClick={() => {
        //@ts-ignore
        NiceModal.show(MyAntdModal, { name: 'Nate', id: 'nateid' })}
      }>
        Show Modal
      </Button>
    </Space>
  );
}

@czkoudy
Copy link

czkoudy commented Sep 8, 2023

Hi @supnate any luck with this?

@supnate
Copy link
Collaborator

supnate commented Oct 2, 2023

Type check now fixed in v1.2.12. You can use id prop now.

@supnate supnate closed this as completed Oct 2, 2023
@chj-damon
Copy link

@supnate I'm using 1.2.13 and still facing the same problem. typescript still reports error because I passed id prop as number type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants