React 高阶组件(hoc)是否应该为上下文相关的道具提供名称?

Should React higher order components (hoc) provide names for props that are contextual?

既然 HOC 应该被用作 mixin,可能与其他 HOC 一起使用,那么注入上下文相关但冗长的 prop 名称是否更可取(例如,以 HOC 的名称为前缀)?

我想这应该被视为最佳实践的问题。

例如,哪个 HOC 更适合注入 window 类行为:

简短的非上下文命名

@window
@otherMixin
class BasicView extends React.Component {
  render() {
    const {close, open} = this.props; //these are provided by @window
  }
}

VS 上下文命名(前缀)

@window
@otherMixin
class BasicView extends React.Component {
  render() {
    const {windowClose, windowOpen} = this.props //these are provided by @window
  }
}

OR 上下文命名(嵌套)

@window
@otherMixin
class BasicView extends React.Component {
  render() {
    const {window} = this.props; //provided by @window
    window.open();
    window.close();

    /*  optionally we can destructure and work with the shorter 
     *  non-contextually named props while still maintaining 
     *  a declaration of their context to disambiguate
     */  
    //const {window: {open, close} } = this.props; 
  }
}

一般来说,库设计者会为它提供反应上下文和一个用于订阅上下文对象的 hoc。您的情况可能是不需要使用上下文。但是,大多数库设计者都受到 "contextual naming (nested)" 的限制,因为上下文就是这样工作的。

这个问题真的只是个人意见问题,但如果你想效仿其他库的模式,那是你应该选择的。

最后一点,出于显而易见的原因,我强烈建议不要证明名为 window 的变量。