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

186
Views
Set Hook in React Native

I can't set a state with Hooks in React Native. After call setMyvariable, I get an [object Object]. I can see that with a simple alert... Please... Help me... Why append this...? This is the code:

import * as React from 'react';
import { useState } from 'react';
import { View, TextInput, Button, StyleSheet } from 'react-native';

const PageArticle = () => {
  const [FindRollNo, setFindRollNo] = useState("12");
  const [RollNo, setRollNo] = useState(undefined);
  const [StudentName, setStudentName] = useState(undefined);
  const [Course, setCourse] = useState(undefined);

  const SearchRecord = () => {
    var FindRollNo = {FindRollNo};
    alert(FindRollNo);
    
  };

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }, styles.viewStyle}>
      <TextInput
          placeholder={'Enter RollNo'}
          placeholderTextColor={'#ff0000'}
          keyboardType={'numeric'}
          style={styles.txtStyle}
          onChangeText={(value) => setFindRollNo(value)}
      />
      <Button title={'Find Record'} onPress={SearchRecord} />
      <TextInput
          style={styles.txtStyle}
          value={RollNo}
      />
      <TextInput style={styles.txtStyle} value={StudentName} />
      <TextInput style={styles.txtStyle} value={Course} />
      {/*<Text>Article Screen ciao </Text>*/}
    </View>
  );
};

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

0

You've wrapped FindRollNo in curly braces, which turns the value into an object.

Fortunately, you can access FindRollNo directly. Here's an Expo Snack showing how:

https://snack.expo.dev/@coolsoftwaretyler/trembling-blueberries

The code looks like this. Pay attention mostly to the difference in SearchRecord, which just alerts FindRollNo directly without creating a new variable or anything.

import * as React from 'react';
import { useState } from 'react';
import { View, TextInput, Button, StyleSheet } from 'react-native';

const PageArticle = () => {
  const [FindRollNo, setFindRollNo] = useState("12");
  const [RollNo, setRollNo] = useState(undefined);
  const [StudentName, setStudentName] = useState(undefined);
  const [Course, setCourse] = useState(undefined);

  const SearchRecord = () => {
    alert(FindRollNo);
  };

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <TextInput
          placeholder={'Enter RollNo'}
          placeholderTextColor={'#ff0000'}
          keyboardType={'numeric'}
          onChangeText={(value) => setFindRollNo(value)}
      />
      <Button title={'Find Record'} onPress={SearchRecord} />
      <TextInput
          value={RollNo}
      />
      <TextInput  value={StudentName} />
      <TextInput value={Course} />
      {/*<Text>Article Screen ciao </Text>*/}
    </View>
  );
};

export default PageArticle
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!