title: How to return variable in React Native?
body: <p>I have an app, where I make a pdf file from given text and picture.</p>
  <p><code>takePicture</code> function in camera component app take a picture, get width and height of it, calculate ratio and save all that info to <code>AsyncStorage</code>. It works fine.</p>
  <p>Problem is when I trying to get that AsyncStorage data in different component.</p>
  <p>Question is: How can I return this <code>const height</code>? I want use it in pdf image drawing. Tried different ways, but none of them working.</p>
  <pre><code>    getImageHeight = async () =&gt; {
          try {
            const height = await AsyncStorage.getItem('asyncimageHeight')
        
            if (height!== null) {
              console.log(`Height from AsyncStorage is: ${height}`)
            }
          } catch (e) {
            alert('Failed to fetch the data from storage')
          }
        }
        getImageHeight();
  </code></pre>
  <p>Here is <code>takePicture</code> if it helps you to get the point of the question:</p>
  <pre><code>takePicture = async() =&gt; {
      
      if (this.camera) {
          const options = { quality: 0.5, base64: true , fixOrientation: true};
          const data = await this.camera.takePictureAsync(options);
          console.log(data.uri);
  
  
          Image.getSize(data.uri, (width, height) =&gt; { // Get image width and height of the picture
              let imageWidth = width;
              let imageHeight = height;
  
              let stringImageWidth = '' + imageWidth; // Makes string for saving in AsyncStorage, allows only strings
              let stringImageHeight = '' + imageHeight;
  
              const horizontalRatioCalc = () =&gt; { // Calculating image ratio for horizontal pictures
                  return (imageWidth/imageHeight);
                };
              
              
              const verticalRatioCalc = () =&gt; {
                  return (imageWidth/imageHeight);
              };
  
              horizontalImageRatio = horizontalRatioCalc();
              verticalImageRatio = verticalRatioCalc();
          
              stringHorizontalImageRatio = '' + horizontalImageRatio;
              stringVerticalImageRatio = '' + verticalImageRatio;
  
              console.log(`Size of the picture ${imageWidth}x${imageHeight}`);
  
  
              horizontalRatio = async () =&gt; {
                  if (imageHeight&gt;imageWidth) {
  
                      verticalRatioCalc();
  
                      try {
                          AsyncStorage.setItem(&quot;imageVerticalRatio&quot;, stringVerticalImageRatio), // Save image ratio, height and width to AsyncStorage
                          AsyncStorage.setItem(&quot;asyncimageWidth&quot;, stringImageWidth),
                          AsyncStorage.setItem(&quot;asyncimageHeight&quot;, stringImageHeight),
                          
                          console.log(`Vertical ratio saved! It's ${stringVerticalImageRatio}`),
                          console.log(`Image Width saved! It's ${stringImageWidth}`),
                          console.log(`Image height saved! It's ${stringImageHeight}`)
      
                      }   catch (e) {
                          console.log(`AsyncStorage saving of image vertical ratio cannot be done.`)
                      }
                  }if (imageHeight&lt;imageWidth) {
                      
                      horizontalRatioCalc();
  
                      try {
                          AsyncStorage.setItem(&quot;imageHorizontalRatio&quot;, stringHorizontalImageRatio),
                          AsyncStorage.setItem(&quot;asyncimageWidth&quot;, stringImageWidth),
                          AsyncStorage.setItem(&quot;asyncimageHeight&quot;, stringImageHeight),
  
                          console.log(`Horizontal ratio saved! It's ${stringHorizontalImageRatio}`),
                          console.log(`Image Width saved! It's ${stringImageWidth}`),
                          console.log(`Image height saved! It's ${stringImageHeight}`)
      
                      }   catch (e) {
                          console.log(`AsyncStorage saving of image vertical ratio cannot be done.`)
                      }
                  }
              }
              horizontalRatio();
  
  
              }, (error) =&gt; {
              console.error(`Cannot size of the image: ${error.message}`);
              
          });
          back(data.uri)
      }
  };
  </code></pre>