我目前正在使用类型化的 React (TSX) 和 mobx 进行状态管理。
我能够构建一个同时使用观察者和注入装饰器的组件。但是我无法构建一个在没有观察者的情况下使用注入的组件。
这通过了打字稿编译器
export const DealershipBreadCrumb = inject("appStore")(observer((props: Props) => {
const {appStore} = props;
const dealership = appStore.getSelectedDealership();
return (
<div className="filter__container filter__group">
<a className="filter__link" href={`cars?q=${appStore.searchResults.searchQuery}`}>
<span className="filter__text">{dealership.name}</span>
</a>
</div>
)
}))
然而这失败了
export const DealershipBreadCrumb = inject("appStore")((props: Props) => {
带有以下错误消息
[ts] Argument of type '(props: Props) => Element' is not assignable to parameter of type 'ComponentClass<{}>'.
Type '(props: Props) => Element' provides no match for the signature 'new (props?: {}, context?: any): Component<{}, ComponentState>'
请协助我制作此错误消息的正面和反面。我敢打赌,打字已经过时了。否则在没有观察者的情况下使用注入实际上是无效的组合。