Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

296
Views
react-native-torch is not working properly

I am trying to use react-native-torch with react native. I took this code and put it into my project. I have also installed react-native-torch with npm install --save react-native-torch. My App.js looks like this (sorry for using code snippet, I wasn't able to achieve propriate formating with this formating):

 import React, { Component } from 'react';
 import {
   AppRegistry,
   Button,
   NativeModules,
   StyleSheet,
   Text,
   View
 } from 'react-native';
 import Torch from 'react-native-torch';
 
 export default class TorchDemo extends Component {
   constructor(props) {
     super(props);
 
     this.state = {
       isTorchOn: false,
     };
   }
 
   _handlePress() {
     const { isTorchOn } = this.state;
     Torch.switchState(!isTorchOn);
     this.setState({ isTorchOn: !isTorchOn });
   }
 
   render() {
     return (
       <View style={styles.container}>
         <Text style={styles.welcome}>
           RCTTorch Demo
         </Text>
         <Button
           onPress={this._handlePress.bind(this)}
           title="Toggle Torch"
         />
       </View>
     );
   }
 }
 
 const styles = StyleSheet.create({
   container: {
     flex: 1,
     justifyContent: 'center',
     alignItems: 'center',
     backgroundColor: '#F5FCFF',
   },
   welcome: {
     fontSize: 20,
     textAlign: 'center',
     margin: 10,
   },
   instructions: {
     textAlign: 'center',
     color: '#333333',
     marginBottom: 5,
   },
 });
 
 AppRegistry.registerComponent('TorchDemo', () => TorchDemo);

Everything runs as it should, but when I tap the toogle torch button, I am getting this warning and the flashlight will not turn on:

expo error

I have tried many forms of their demo codes, but the problem was always with Torch.switchState. Does anyone knows how to fix this issue?
Thank you very much for any help.
Jan

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Did you try building the app again as this module requires linking? If not, you need to run the React Native app again.

For android run: npx react-native run-android

For ios run: npx react-native run-ios

about 4 years ago · Juan Pablo Isaza Report

0

It looks like you're using a managed workflow, it won't work through Expo Go. You need to use a development client for native code to work. Create it with EAS.

  1. Install the expo-dev-client library expo install expo-dev-client
  2. Create an eas.json eas build:configure
  3. Build client and install on device/emulator eas build -p android --profile development
  4. Use expo start --dev-client instead of 'expo start'

Docs: https://docs.expo.dev/development/getting-started/

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!