Is it possible to capitalize first letter of text/string in react native? How to do it?

Solution 1:

Write a function like this

Capitalize(str){
return str.charAt(0).toUpperCase() + str.slice(1);
}

then call it from <Text> tag By passing text as parameter

<Text>{this.Capitalize(this.state.title)} </Text>

Solution 2:

You can also use the text-transform css property in style:

<Text style={{textTransform: 'capitalize'}}>{this.state.title}</Text>

Solution 3:

React native now lets you make text uppercase directly with textTransform: 'capitalize'. No function necessary.

import React from 'react'
import { StyleSheet, Text } from 'react-native'

// will render as Hello!
const Caps = () => <Text style={styles.title}>hello!</Text>

export default Caps

const styles = StyleSheet.create({ 
 title: { 
   textTransform: 'capitalize'
 }
})