Navigate back to the homepage

how to return a string from function in react native?

Infinitbility
React Native
June 22nd, 2022 · 1 min read

Hi Friends 👋,

Welcome To Infinitbility! ❤️

To use string from function in react native, just use the like ${function()}/hello syntax to call a function and concat in a string.

Like the following example, we can create a function that return a string and uses a function in a react native render function.

1const getLink= () => {
2 const url = 'https://infinitbility.com/'
3 return url;
4}
5
6
7const link = `${getLink()}about`; // https://infinitbility.com/about

Today, I’m going to show you How do i return and use a string from a function in react native, as above mentioned here, I’m going to use some basic syntax of ECMAScript.

Let’s start today’s tutorial how do you return and use a string from a function in react native?

In this example, we will do

  1. Create samples return string function.
  2. Use the function with tiny ( ` ) in react native render.
  3. Print the Output on the screen
1import React, { useState, useEffect } from 'react';
2import { Text, View, StyleSheet } from 'react-native';
3
4export default function App() {
5
6 const getLink= () => {
7 const url = 'https://infinitbility.com/'
8 return url;
9 }
10
11 return (
12 <View style={styles.container}>
13 <Text>{`${getLink()}about`}</Text>
14 </View>
15 );
16}
17
18const styles = StyleSheet.create({
19 container: {
20 flex: 1,
21 justifyContent: 'center',
22 backgroundColor: '#ecf0f1',
23 padding: 8,
24 },
25 paragraph: {
26 margin: 24,
27 fontSize: 18,
28 fontWeight: 'bold',
29 textAlign: 'center',
30 },
31});

As mentioned above, we are taken the example of a return string function, use string function in react native render, concat with string, and printed on the screen.

Let’s check the output.

React Native, return and use a string from function example
React Native, return and use a string from function example
  • Try it yourself

I hope it’s help you, All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

how to convert boolean to string in react native?

Example of to convert boolean to string react native with step by step guide.

June 21st, 2022 · 1 min read

how to convert string to date in react native?

Example of to convert string to date react native with step by step guide.

June 21st, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]