简体   繁体   中英

How to capitalize a Moment component in React-Native

I have the following component:

<Moment element={Text}
        format="MMM DD, YYYY \at h:mma"
        style={dateStyle}
>
    {this.props.updateDate}
</Moment>

It's currently ouputting something like Jan 01, 2017 at 12:53pm , but I need it to output JAN 01, 2017 AT 12:53PM instead.

Normally you would use {string.toUppercase()} to achieve this, but I'm having issues figuring out how to get at the output.

Any help would be greatly appreciated. Thanks!

At the time I responded initially in 2017, I was wrong to suggest that one could simply use the CSS text-transform: uppercase . React-Native doesn't use traditional CSS, but uses JavaScript to add styles .

At the time, this was not supported by React-Native. I should have deleted the answer.

However, since then, the Text Component style property now supports:

textTransform: 'uppercase'

https://facebook.github.io/react-native/docs/text#style

Create your own UpperText component and pass that to Moment as element . In your UpperText component, apply toUppercase() to its string child and return Text with the uppercase text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM