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

Uncaught The provide prop was not found on the parent node or the provide type is incorrect. provide和inject的使用问题 #860

Closed
GuYith opened this issue Oct 5, 2023 · 3 comments

Comments

@GuYith
Copy link
Contributor

GuYith commented Oct 5, 2023

我现在在实现avatar组件,其中的avatar group需要获取父组件的size,在React中可以使用Context实现,在omi中我目前能想到的解决方式是使用provide和inject实现

我在avatar-group中添加了如下代码:

  install() {
    this.provide = { groupSize: this.props.size }
  }

在avatar组件中添加了如下代码:

  inject = ['groupSize']

当使用avatar-group的时候,可以正常工作,但是在没有使用avatar-group的时候出现了报错
image
image
导致avatar组件无法正常显示

我希望provide为undefine的时候不抛出错误,是否可以设置injection为空?或者有什么其他更好的方式实现类似功能

@dntzhang
Copy link
Collaborator

dntzhang commented Oct 6, 2023

赞,我看一下。

@dntzhang
Copy link
Collaborator

dntzhang commented Oct 6, 2023

v6.25.22。把throw去掉了

@GuYith
Copy link
Contributor Author

GuYith commented Oct 6, 2023

v6.25.22。把throw去掉了

好嘞!

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

2 participants