これは何をしようとしているのかの例です。 MyComponentを他のライブラリに渡しているので、<MyComponent hello={'Hello World'}/>
を使わずにMyComponentクラスの小道具を渡したいと思います。reactjs、クラスレベルで小道具を渡す方法
react-reduxはthis.props.stateを追加するためにどのように接続し、他の機能をコンポーネントの小道具にマッピングしますか?カスタムオブジェクトをコンポーネントに挿入したい
これは何をしようとしているのかの例です。 MyComponentを他のライブラリに渡しているので、<MyComponent hello={'Hello World'}/>
を使わずにMyComponentクラスの小道具を渡したいと思います。reactjs、クラスレベルで小道具を渡す方法
react-reduxはthis.props.stateを追加するためにどのように接続し、他の機能をコンポーネントの小道具にマッピングしますか?カスタムオブジェクトをコンポーネントに挿入したい
function withMyObject(WrappedComponent,helloText) {
return class extends React.Component {
render() {
return <WrappedComponent {...this.props} hello={helloText} />;
}
};
}
使用法を作成する必要があります:あなたは、デフォルトの小道具を設定することができ
UpdatedComponent = withMyObject(ComponentToBeWrapped,"Hello");
を。私はその良い習慣だと思う。
import React, { Component } from 'react';
class MyComponent extends Component {
render() {
const { hello } = this.props;
return (
<div>{hello}</div>
);
}headerProp: "Header from props...",
contentProp:"Content from props..."
}
MyComponent.defaultProps = {
hello: 'Hello World!'
}
<MyComponent />
あなたが求めていることを考えてください。あなたは小道具を渡すことなく、小道具を渡したい。いいえ、それはあなたがリアクションの方法論をどのように使うのかではありません。あなたの例では 'let props = {...}'と言って、それがうまくいくので ' 'を使ってください:これをしたくない理由はありません。プログラミングの観点から見てください。 –