Javascript 如何获得组件外部的React道具

Javascript 如何获得组件外部的React道具,javascript,reactjs,Javascript,Reactjs,我需要一种方法来加载这个脚本的正确语言,并且该信息是一个道具值。粗略地说,它看起来是这样的: class AddressInput extends React.Component { render() { return ( <PlacesAutocomplete do={this.someStuff} /> ); } } export default scriptLoader( `https://maps.goog

我需要一种方法来加载这个脚本的正确语言,并且该信息是一个道具值。粗略地说,它看起来是这样的:

class AddressInput extends React.Component {
  render() {
    return (
      <PlacesAutocomplete
        do={this.someStuff}
      />
    );
  }
}

export default scriptLoader(
  `https://maps.googleapis.com/maps/api/js?&language=${this.props.language}`;
)(connect(mapStateToProps, mapDispatchToProps)(AddressInput));
类地址输入扩展了React.Component{
render(){
返回(
);
}
}
导出默认脚本加载器(
`https://maps.googleapis.com/maps/api/js?&language=${this.props.language}`;
)(连接(MapStateTrops,mapDispatchToProps)(地址输入));

我知道,
this.props
在组件之外是不可访问的,那么我如何才能获取
scriptLoader
以获取动态值呢?

基本上就是这样。你甚至有把它变成一个临时的想法。以下是执行情况:

function scriptLoader(WrappedComponent) {
  return (props) => {
    const dynamicUrl = `https://maps.googleapis.com/maps/api/js?&language=${props.language}`;
    return <WrappedComponent {...props} url={dynamicUrl}/>
  }
}

能否为
脚本加载器添加代码?或者可以创建一个codesandbox?您不必在导出时连接组件,只需在
语言
范围内连接它即可
// usage in the parent
<AddressInput language="en"/>

// what is available in your presentational component
class AddressInput extends React.Component {
  render() {
    console.log(this.props.url) // https://maps.googleapis.com/maps/api/js?&language=us
    return (
      <PlacesAutocomplete
        do={this.someStuff}
      />
    );
  }
}