Hi Friends đź‘‹,
Welcome To Infinitbility! ❤️
To concat string in react native, just use the +
plus operator it will concatenate two strings and show on the screen.
Today, I’m going to show you how do i append strings in another string in react native, as above mentioned we will use +
plus operator to concatenate strings.
Let’s start today’s topic how to concat string in react native?
Here we will see an example of showing two state strings in a single text using +
plus operator to concat them.
let’s start
import React, { useState, useEffect } from 'react';
import { Text, View, StyleSheet } from 'react-native';
export default function App() {
const [firstString, setFirstString] = useState('Hi');
const [secondString, setSecondString] = useState('Infintbility');
useEffect(() => {
let result = firstString + ' ' + secondString;
console.log(result);
}, []);
return (
<View style={styles.container}>
<Text>{firstString + ' ' + secondString}</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: '#ecf0f1',
padding: 8,
},
paragraph: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
},
});
Here, we will use ' '
for append space between both words. let’s check the output.
I hope it’s help you, All the best đź‘Ť.