react-timeago
npmモジュールを使用したい単純なReactアプリケーションがあります
そして私はドキュメントを見ました、そこで私が使いたい関数があります
formatter (optional)
A function that takes four arguments:
value : An integer value, already rounded off
unit : A string representing the unit in english. This could be one of:
'second'
'minute'
'hour'
'day'
'week'
'month'
'year'
suffix : A string. This can be one of
'ago'
'from now'
epochSeconds: The result of Date.now() or the result of a custom now prop.
nextFormatter: A function that takes no arguments and gives you the result of the defaultFormatter using the same arguments above.
これはドキュメントに小道具として表示されていますが、関数に小道具として引数を渡すにはどうすればよいですか?
<TimeAgo date={this.state.time} formatter={/*how can i pass in the arguments to the function */} live={true}/>
ここでコンポーネントを呼び出しましたが、適切な小道具をコンポーネントに渡す方法がわかりませんか?
内部で使用する関数をformatter
小道具に与えreact-timeago
ます。
例
<TimeAgo
date={this.state.time}
formatter={(value, unit, suffix) => `${value} ${unit} ${suffix}`}
live={true}
/>
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加