Uncaught The provide prop was not found on the parent node or the provide type is incorrect. provide和inject的使用问题
GuYith opened this issue · comments
我现在在实现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的时候出现了报错
导致avatar组件无法正常显示
我希望provide为undefine的时候不抛出错误,是否可以设置injection为空?或者有什么其他更好的方式实现类似功能
赞,我看一下。
v6.25.22。把throw去掉了
v6.25.22。把throw去掉了
好嘞!