Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
[ad_1]
I wish to use getter/setter operate to set the state of my textual content enter discipline. and I am utilizing mannequin class and accessing the setter getter operate in my Registration class however could not in a position to set state. Any assist relating to this matter can be actually appreciated.
My modelclass.js:
class UserModel {
stateName="";
username;
electronic mail;
cell;
gender;
deal with;
constructor() {}
setStateName(stateName) {
this.stateName = stateName;
}
getStateName(){
return this.stateName;
}
setUserName(username) {
this.username = username;
}
setEmail(electronic mail) {
this.electronic mail = electronic mail;
}
setMobile(cell) {
this.cell = cell;
}
setGender(gender) {
this.gender = gender;
}
setAddress(deal with) {
this.deal with = deal with;
}
}
const GlobalUserModel = new UserModel();
export default GlobalUserModel;
My RegistrationClass.js
var db = openDatabase({ identify: 'UserDatabase.db' });
const RegistrationScreen = ({ navigation }) => {
useEffect(() => {
db.transaction(operate (txn) {
txn.executeSql(
"SELECT identify FROM sqlite_master WHERE kind="desk" AND identify="table_user"",
[],
operate (tx, res) {
console.log('merchandise:', res.rows.size);
if (res.rows.size == 0) {
txn.executeSql('DROP TABLE IF EXISTS table_user', []);
txn.executeSql(
'CREATE TABLE IF NOT EXISTS table_user(user_id INTEGER PRIMARY KEY AUTOINCREMENT, user_name VARCHAR(20), user_contact INT(10), user_address VARCHAR(255))',
[]
);
}
}
);
});
}, []);
// let [stateName ,setStateName] = useState('');
let [userContact, setUserContact] = useState('');
let [userAddress, setUserAddress] = useState('');
let register_user = () => {
console.log(GlobalUserModel.stateName, userContact, userAddress);
if (!GlobalUserModel.getStateName) {
alert('Please fill identify');
return;
}
if (!userContact) {
alert('Please fill Contact Quantity');
return;
}
if (!userAddress) {
alert('Please fill Handle');
return;
}
db.transaction(operate (tx) {
console.log(GlobalUserModel.getStateName(), userContact, userAddress);
tx.executeSql(
'INSERT INTO table_user (user_name, user_contact, user_address) VALUES (?,?,?)',
[GlobalUserModel.stateName, userContact, userAddress],
(tx, outcomes) => {
console.log('Outcomes', outcomes.rowsAffected);
if (outcomes.rowsAffected > 0) {
Alert.alert(
'Success',
'You might be Registered Efficiently',
[
{
text: 'Ok',
onPress: () => navigation.navigate('HomeScreen'),
},
],
{ cancelable: false }
);
} else alert('Registration Failed');
}
);
});
};
return (
<View fashion={kinds.inputWrap}>
<Textual content fashion={kinds.EdittextHeading}>Household Quantity</Textual content>
<TextInput fashion={kinds.Edittext}
placeholder="Auto Generate"
keyboardType="numeric"
// editable={false}
// selectTextOnFocus={false}
placeholderTextColor="#30A28C"
onChangeText= {GlobalUserModel.setStateName} />
</View>
[ad_2]