React Native TypeError: Cannot read property 'timeSlots' of undefined - react-native

I want to display the selected Date, Start Time, and End Time when user presses the Add Appointment Button. However, when I press the add appointment button, the data gets added to my database but it fails to show it on the FlatList.
Code snippet provided below (If full code is required I can provide it):
export default class FrCreateScreen extends Component {
addTimeDateAppt() {
let self = this;
AsyncStorage.getItem('my_token').then(keyValue => {
console.log('Freelancer Create Screen (keyValue): ', keyValue);
axios({
method: 'post',
url: Constants.API_URL + 'appointment_f/create_appointment/',
//responseType: 'json',
data: {
app_date_start: this.state.textAppointmentDate,
start_time: this.state.textAppointmentTime,
end_time: this.state.textEndTime,
},
headers: {
'X-API-KEY': Constants.API_KEY,
Authorization: keyValue,
},
})
.then(function(response) {
this.setState({
timeSlots: [
...this.state.timeSlots,
{
apptdate: this.state.textAppointmentDate,
appttime: this.state.textAppointmentTime,
endTime: this.state.textEndTime,
},
],
});
console.log(response.data);
})
.catch(function(error) {
console.log('Create Error: ', error);
});
});
}
deleteDateTime = id => {
const filteredData = this.state.timeSlots.filter(item => item.id !== id);
this.setState({ timeSlots: filteredData });
};
render() {
return (
<ScrollView>
{this.getAppointmentDatePage()}
{this.getAppointmentTimePage()}
{this.getEndTimePage()}
<TouchableOpacity
style={styles.addContainer}
onPress={() => this.addTimeDateAppt()}
>
<Text style={styles.addText}> Add Appointment </Text>
</TouchableOpacity>
<View>
<FlatList
data={this.state.timeSlots}
keyExtractor={({ id }, index) => index.toString()}
renderItem={({ item, index }) => {
return (
<View style={styles.containerList}>
<View style={styles.dateList}>
<Text style={{ fontWeight: 'bold' }}>Date: </Text>
<Text style={styles.textTime}>{item.apptdate}</Text>
</View>
<View style={styles.row}>
<View>
<Text style={{ fontWeight: 'bold' }}>Start Time:</Text>
<Text style={styles.textTime}>{item.appttime}</Text>
</View>
<View>
<Text style={{ fontWeight: 'bold' }}>End Time:</Text>
<Text style={styles.textTime}>{item.endTime}</Text>
</View>
<TouchableOpacity
onPress={() => this.deleteDateTime(item.index)}
>
<Feather name="trash" style={styles.icon} />
</TouchableOpacity>
</View>
</View>
);
}}
/>
</View>
</ScrollView>
);
}
}
Screenshot:

The error implies that 'state' doesn't exist.
Have you tried changing the method into an arrow function, i.e.
addTimeDateAppt = () => {...}
This will bind the method to the instance of your component, and references to 'this.state' will work.
Also you've declared the variable 'self' referring to 'this', but then proceed to use 'this' anyway in the method. Not sure if this is intentional but you shouldn't need it if you use the arrow syntax.

Related

In React Native can I setState to an object that is in an api call?

This should be something so incredibly easy, but I'm struggling really hard on this. All I want to do is setState of id to "results.id" from my api call. Once it changes the state to what is inside of the api, I will then be able to successfully open up the filmography api. I've tested the axios fetch url by putting in a real id, and it works. So I'm basically trying to grab the id that I get from a search, and update the id state with THAT id. If I'm trying to setState in the wrong function, then by all means help me get it in the right function! (Also I know I have some sloppy code, but a lot of it is personal notes for me until I'm ready to save it for good)
import React, { useState } from "react";
import {
View,
TextInput,
Button,
Text,
ActivityIndicator,
ScrollView,
Image,
TouchableHighlight,
Alert,
} from "react-native";
import Modal from "react-native-modal";
import axios from "axios";
export default function Screen4() {
// id is a 2 digit number for specific actor const apiurl5 = "http://api.tmdb.org/3/search/person?api_key=84c329a92566be57845322a19ff707ac&query=" const apiurl4 = "/movie_credits?api_key=84c329a92566be57845322a19ff707ac&language=en-US" const apiurl3 = "https://api.themoviedb.org/3/person/" const apiurl2 = "https://api.themoviedb.org/3/movie/upcoming?api_key=84c329a92566be57845322a19ff707ac&language=en-US&page=1"; const apiurl = "http://www.omdbapi.com/?apikey=7ad73765&"; const [state, setState] = useState({ s: "Enter an actor...", id: "", results: [], selected: [], modalVisible: false, modalVisible2: false });
const search = () => {
// apiurl + "&t=" + state.s (Single Result)
// apiurl + "&s=" + state.s (Multiple Results)
axios(apiurl5 + state.s).then(({ data }) => {
//let results = [data]; ----- ******** Use this for &t= **************** -------------
//let results = data.Search; ----- ******** Use this for &s= **************** -------------
let results = data.results;
let id = state.id;
setState((prevState) => {
return { ...prevState, modalVisible: true };
}),
setState((prevState) => {
return { ...prevState, results: results };
}),
setState((prevState) => {
return { ...prevState, id: id };
}),
Alert.alert("The ID is: ", id, [
{ text: "Close", onPress: () => console.log("alert closed") },
]);
});
};
const openPopup = () => {
axios(apiurl3 + state.id + apiurl4).then(({ data }) => {
let result = data.cast;
setState((prevState) => {
return { ...prevState, modalVisible2: true };
}),
setState((prevState) => {
return { ...prevState, selected: result };
});
});
};
return (
<View style={{ flex: 1, padding: 10, justifyContent: "center" }}>
<Text>Cinemaster!</Text>
<TextInput
style={{
borderBottomWidth: 1,
borderBottomColor: "#ff0000",
marginBottom: 20,
}}
onChangeText={(text) =>
setState((prevState) => {
return { ...prevState, s: text };
})
}
onSubmitEditing={search}
value={state.s}
/>
<Button onPress={search} title="Search"></Button>
{/* key=result.imdbID -
This gives multiple search results with the &s= is in the URL
key=result -
This gives the result with the &t= is in the URL */}
<Modal
//animationType="slide"
transparent={false}
//visible={(state.modalVisible)}
animationIn="slideInRight"
animationOut="slideOutLeft"
useNativeDriver={true}
isVisible={state.modalVisible}
>
<ScrollView>
{state.results.map((results, index) => (
<TouchableHighlight key={index}>
<View style={{ flex: 1, padding: 10, justifyContent: "center" }}>
<Button title="Full Filmography" onPress={openPopup}></Button>
<Text>Gender: {results.gender}</Text>
<Text>ID: {results.id}</Text>
{results.known_for.map((k, i) => (
<TouchableHighlight
key={i}
// onPress={() => openPopup()}
>
<View>
<Text>Title: {k.title}</Text>
<Image
source={{
uri:
"https://image.tmdb.org/t/p/original/" +
k.poster_path,
}}
style={{ width: 300, height: 500 }}
resizeMode="cover"
/>
</View>
</TouchableHighlight>
))}
{/* <Text>Title: {results.gender}</Text> -----THIS ALSO WORKS----- */}
{/* {dataItems.map((item, index) => (
<div key={index}>
<h1>{item.title}</h1>
{item.content.map((c, i) => (
<div key={i}>
<img src={c.imageUrl} />
<h3>{c.title}</h3>
<h3>{c.description}</h3>
<hr />
</div>
))}
</div>
))} */}
</View>
</TouchableHighlight>
))}
<Text
onPress={() =>
setState((prevState) => {
return { ...prevState, modalVisible: false };
})
}
style={{
marginTop: 50,
color: "red",
fontSize: 40,
fontWeight: "bold",
}}
>
Close!
</Text>
</ScrollView>
</Modal>
{/* animationType in Modal can be fade, none, or slide */}
<Modal
//animationType="slide"
transparent={false}
//visible={(state.modalVisible)}
animationIn="slideInRight"
animationOut="slideOutLeft"
useNativeDriver={true}
isVisible={state.modalVisible2}
>
<ScrollView>
{state.selected.map((cast, index2) => (
<View key={index2}>
<Text>Title:{cast.title} </Text>
<Text>Overview:{cast.overview} </Text>
</View>
))}
</ScrollView>
<TouchableHighlight
onPress={() =>
setState((prevState) => {
return { ...prevState, modalVisible2: false };
})
}
>
<Text
style={{
marginTop: 50,
color: "red",
fontSize: 40,
fontWeight: "bold",
}}
>
Close!
</Text>
</TouchableHighlight>
</Modal>
</View>
);
}
API for results.id :
http://api.tmdb.org/3/search/person?api_key=84c329a92566be57845322a19ff707ac&query=tom%20hanks
API for filmography:
https://api.themoviedb.org/3/person/31/movie_credits?api_key=84c329a92566be57845322a19ff707ac&language=en-US
Attached an image, showing the ID I'm trying to setState inPhoneExample
I figured it out. I had to use a for loop in order to get the data I needed in order to then set that data. What wasn't clear to me at first, was if that was necessary or not, and if it was I assumed I had to do that in the section of my code where I was mapping things. But no, once I got a for loop going in that search function it started to make sense to me.

Retrieve a list of products and display them

I am trying to retrieve a list of products from my API. For the moment, nothing is displayed, the page is currently empty except for my back button and I do not understand why. The two functions I use are functional since both console.log works. Could you help me ?
Everything looks fine, the console.log work in the terminal but I can't display anything in the app.
I tried this snack : https://snack.expo.io/O4oPj8-Qz
const Item = ({ item, onPress, style }) => (
<TouchableOpacity onPress={onPress} style={[styles.productItem, style]}>
<Text style={[styles.h4, {textAlign: "left"}]}>
{item.name}
</Text>
</TouchableOpacity>
);
export default class Products extends Component {
constructor(props) {
super(props);
this.state = {
selectedId: '',
setSelectedId: '',
listData: '',
currentPage: 1,
loadMoreVisible: true,
loadMoreVisibleAtEnd: false,
displayArray: null
}
};
initListData = async () => {
let list = await getProducts(1);
console.log(list)
if (list) {
this.setState({
displayArray: list,
loadMoreVisible: (list.length >= 15 ? true : false),
currentPage: 2
});
}
};
setNewData = async (page) => {
let list = await getProducts(parseInt(page));
if (list) {
this.setState({
displayArray: this.state.displayArray.concat(list),
loadMoreVisible: (list.length >= 15 ? true : false),
loadMoreVisibleAtEnd: false,
currentPage: parseInt(page)+1
});
}
};
loadMore() {
this.setNewData(this.state.currentPage);
}
displayBtnLoadMore() {
this.setState({
loadMoreVisibleAtEnd: true
});
}
async UNSAFE_componentWillMount() {
this.initListData();
}
render() {
return (
<View>
{this.state.displayArray !== null && this.state.displayArray.length > 0 ? (
<View style={{ flex: 1, marginBottom: 100 }}>
<SafeAreaView style={styles.container}>
<FlatList
data={this.state.displayArray}
extraData={this.selectedId}
onEndReached={() => this.displayBtnLoadMore()}
renderItem={({item})=>
<View style={{flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center'}}>
<Item
item={item}
onPress={() => this.props.navigation.navigate('ProductDetails', {productId: parseInt(item.id)})}
/>
</View>
}
keyExtractor={item => "product-" + item.id.toString()}
style={{width:"90%"}}
/>
{this.state.loadMoreVisible === true && this.state.loadMoreVisibleAtEnd === true ? (
<Button title=" + " onPress={()=>{this.loadMore()}}></Button>
) : null
}
<View style={styles.container}>
<Text>{"\n"}</Text>
<TouchableOpacity
style={styles.touchable2}
onPress={() => this.props.navigation.goBack()}
>
<View style={styles.view2}>
<Text style={styles.textimg2}>
back
</Text>
</View>
</TouchableOpacity>
</View>
<Text>{"\n\n"}</Text>
</SafeAreaView>
</View>
) : (
<View style={styles.container}>
<Text>{"\n\n" + (this.state.displayArray === null ? i18n.t("products.searching") : i18n.t("products.nodata")) + "\n\n\n"}</Text>
<TouchableOpacity
style={styles.touchable2}
onPress={() => this.props.navigation.goBack()}
>
<View style={styles.view2}>
<Text style={styles.textimg2}>
Back
</Text>
</View>
</TouchableOpacity>
</View>
)}
</View>
);
};
}
You were not adding flex: 1 and also not calling the API in the right way, here is the snack with the solution.
Link to snack
Thanks to your answers and help. I got it work this way : Thank you so much for yout time and help, really, sincerely.
import React, { Component } from "react";
import { FlatList, SafeAreaView, Button, Text, View, TouchableOpacity } from 'react-native';
import { getProducts } from '../../../src/common/Preferences';
import styles from '../../../assets/styles';
import i18n from '../../../src/i18n';
const Item = ({ item, onPress, style }) => (
<TouchableOpacity onPress={onPress} style={[styles.productItem, style]}>
<Text style={[styles.h4, {textAlign: "left"}]}>
{item.name}
</Text>
</TouchableOpacity>
);
export default class Products extends Component {
constructor(props) {
super(props);
this.state = {
selectedId: '',
setSelectedId: '',
listData: '',
currentPage: 1,
loadMoreVisible: true,
loadMoreVisibleAtEnd: false,
displayArray: []
}
};
initListData = async () => {
let list = await getProducts(1);
if (list) {
this.setState({
displayArray: list,
loadMoreVisible: (list.length >= 15 ? true : false),
currentPage: 2
});
console.log(this.state.displayArray, 'dans initListData')
}
};
setNewData = async (page) => {
let list = await getProducts(parseInt(page));
if (list) {
this.setState({
displayArray: this.state.displayArray.concat(list),
loadMoreVisible: (list.length >= 15 ? true : false),
loadMoreVisibleAtEnd: false,
currentPage: parseInt(page)+1
});
}
};
loadMore() {
this.setNewData(this.state.currentPage);
}
displayBtnLoadMore() {
this.setState({
loadMoreVisibleAtEnd: true
});
}
async UNSAFE_componentWillMount() {
this.initListData();
console.log(this.state.displayArray, 'dans componentWillMount')
}
render() {
console.log('displayArray', this.state.displayArray)
return (
<View style={{flex: 1}}>
<Text>{"\n"}</Text>
<Text>{"\n"}</Text>
{this.state.displayArray !== null && this.state.displayArray.length > 0 ? (
<View style={{ flex: 1, marginBottom: 100 }}>
<SafeAreaView style={styles.container}>
<FlatList
data={this.state.displayArray}
//extraData={this.selectedId}
//onEndReached={() => this.displayBtnLoadMore()}
renderItem={({item})=>
<View style={{flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center'}}>
<Item
item={item}
onPress={() => this.props.navigation.navigate('ProductDetails', {productId: parseInt(item.id)})}
/>
</View>
}
keyExtractor={item => "product-" + item.id.toString()}
style={{width:"90%"}}
/>
{this.state.loadMoreVisible === true && this.state.loadMoreVisibleAtEnd === true ? (
<Button title=" + " onPress={()=>{this.loadMore()}}></Button>
) : null
}
<View style={styles.container}>
<Text>{"\n"}</Text>
<TouchableOpacity
style={styles.touchable2}
onPress={() => this.props.navigation.goBack()}
>
<View style={styles.container}>
<Button
color="#F78400"
title= 'Back'
onPress={() => this.props.navigation.goBack()}>BACK
</Button>
</View>
</TouchableOpacity>
</View>
<Text>{"\n\n"}</Text>
</SafeAreaView>
</View>
) : (
<View style={styles.container}>
<Text>{"\n\n" + (this.state.displayArray === null ? i18n.t("products.searching") : i18n.t("products.nodata")) + "\n\n\n"}</Text>
<Button
color="#F78400"
title= 'Back'
onPress={() => this.props.navigation.goBack()}>BACK
</Button>
</View>
)}
</View>
);
};
}

React Native TypeError: undefined is not a function (near '...this.state.clubs.map...')

I am having trouble displaying my api data in the app, i feel like it has something to do with the way i want to map the data.
When i use my 1st api it works but it is not the right one because it shows all the clubs info not a single club.
Here is the postman:
Here is the console:
This is what is displays in the app:
The problem I am having is that when i use my 2nd api link that allows me to get a single clubs data i get an error when mapping it.
Here is my code, the only thing i changed was the api link, I also tried to use c.club.numberOfCheckIns but it didnt work either.
class Profile extends React.Component {
constructor(props) {
super(props)
this.state = {
clubInfo: []
};
}
componentDidMount() {
this._get('http://ec2-3-15-176-119.us-east-2.compute.amazonaws.com:8080/clubs/get/1').then(
data => {
this.setState({ clubInfo: data })
}
)
}
_get = async (endpoint) => {
const res = await fetch(endpoint, {
headers: {
'Content-Type': 'application/json',
'Access-Token': '1*adminaccesstoken'
}
})
const data = await res.json();
console.log(data)
return data;
}
renderClubData() {
return this.state.clubInfo.map((c, index) => {
const { clubId, name, city, country, email, verified } = c //destructuring
return (
<View key={c.clubId}>
<Text
bold
size={20}
color="#B8AA5B"
style={{ marginBottom: 4 }}
>{c.numberOfCheckIns}
</Text>
</View>
)
})
}
render() {
return (
<Block flex style={styles.profile}>
<Block flex>
<ImageBackground
source={{ uri: Images.EventPhoto }}
style={styles.profileContainer}
imageStyle={styles.profileBackground}
>
<ScrollView
showsVerticalScrollIndicator={false}
style={{ width, marginTop: '55%' }}
>
<Block flex style={styles.profileCard}>
<Block style={styles.info}>
<Block middle style={{ marginTop: 10, paddingBottom: 10 }} row space="between">
<Block middle>
{this.renderClubData()}
<Text size={12}>CHECK-INS</Text>
</Block>
Here is the postman:
I figured it out:
componentDidMount() {
this._get('API').then(
data => {
this.setState( {clubInfo: [data]})
}
)
}
renderClubData() {
return this.state.clubInfo.map((c, index) => {
return (
<View key={c.club.clubId}>
<Text bold size={20} color="#B8AA5B" style={{ marginBottom: 4 }} >
{c.club.numberOfCheckIns}
</Text>
</View>
)
})
}
I used [] for data to turn the JSON into an array.
The problem is the way you handle this.state.clubInfo.map() method. In order to use map method, you need to pass an array.
That is why it is worked previously because you send an array of data to this.state.clubInfo.map().
Change your renderClubData() as below because now you are getting an object as a result of the API request.
renderClubData() {
return (
<View key={c.clubId}>
{
this.state.clubInfo.club.numberOfCheckIns &&
<Text bold size={20} color="#B8AA5B" style={{ marginBottom: 4 }}>
{this.state.clubInfo.club.numberOfCheckIns}
</Text>
}
</View>
)
}
#DevAS is also right. you can try [this.state.clubInfo].map() as below,
renderClubData() {
return [this.state.clubInfo].map((c, index) => {
return (
<View key={c.club.clubId}>
<Text bold size={20} color="#B8AA5B" style={{ marginBottom: 4 }} >
{c.club.numberOfCheckIns}
</Text>
</View>
)
})
}
I hope this will helps you.

Axios post with TextInput values not working with no trailing error

I am trying to pass some parameters from TextInput to the body in Axios. It doesn't display any error or return a status using console.log().
I have several ways to see what could have been the problem. I tried to pass the function to ComponentDiDMount and some other components lifecycles with no success. I have also passed the values directly, used Json.parse(), JSON.encode(), JSON.stringify(), no error and yet not returning status. I know there might be a mistake I am making.
More also, I don't know if I am doing this wrongly. I try to fetch data to a dropdown from which I need to use the key to pass the corresponding id of the selected value to category_id. When the page loads, it fetches "category" i.e a field name with corresponding id to the dropdown but only the corresponding is needed to pass to the Axios.post.
import React, { Component } from 'react';
import {
Text,
TextInput,
View,
Image,
TouchableOpacity,
Button,
StyleSheet} from 'react-native';
import { Dropdown } from 'react-native-material-dropdown';
import axios from 'axios';
export default class CreatePost extends Component {
constructor(props){
super(props)
this.state = {
category: [],
title: '',
cat: '',
author:'',
body:''
}
}
static navigationOptions = ()=> {
return{
title: null,
headerStyle: { backgroundColor: '#1A5276', color:'#fff' },
header:null
}
};
componentWillMount(){
axios.get(`http://localhost/rest_api_myblog/api/category/read.php`)
//.then(json => console.log(json.data.data[0].name))
.then(json => json.data.data)
.then(newData => this.setState({category: newData}))
.catch(error => alert(error))
}
onChangeTextPress(key, value){
this.setState((prevState) => {
//let selected = Object.assign({}, prevState.selected);
let selected = Object.assign({},prevState.selected);
selected[key] = value;
return { selected };
}, () => {
this.setState({ cat: this.state.selected[key]});
// console.log(cat);
});
}
onCreate = event => {
event.preventDefault();
const body = {
author :this.state.author,
title : this.state.title,
body : this.state.body,
category_id :this.state.cat
};
axios.post(`http://localhost/rest_api_myblog/api/post/create.php`, JSON.parse(body))
.then(res => {console.log(res)
})
.catch(e => console.log(e));
}
render() {
const data = this.state.category.map((cat, i) =>({
value: cat.name,
key: i
}));
return (
<View style= {styles.container}>
<View><Image style={styles.image} source={require('../images/blog.jpg')}/>
<Text style={styles.header}>Create Post</Text></View>
<View style={{alignItems:'center'}}>
<Text style= {styles.label}>Title</Text>
<TextInput
style={styles.textbox}
placeholder="Title"
onChangeText= {(title)=>{
this.setState({title});
}}
value={this.state.title}/>
<Text style= {styles.label}>Author</Text>
<TextInput
style={styles.textbox}
name='author'
placeholder="Author"
onChangeText= {(text)=>{
this.setState({author: text});
}}
value={this.state.author}
/>
<Text style= {styles.label}>Category</Text>
<Dropdown
dropdownOffset={{top:5, left: 0 }}
containerStyle={{
borderWidth:1,
borderColor:'lightgrey',
borderRadius:13, width:300, height: 40,
paddingLeft:6,
backgroundColor:'#fff'}}
rippleCentered={true}
inputContainerStyle={{ borderBottomColor: 'transparent' }}
data = {data}
valueExtractor={({value})=> value}
onChangeText={(value, key)=>{this.onChangeTextPress( value, key)}}
/>
<Text style= {styles.label}>Body</Text>
<TextInput
style={styles.textbox}
multiline = {true}
numberOfLines = {4}
placeholder="Body"
onChangeText= {(body)=>{
this.setState({body});
}}
value={this.state.body}
/>
<TouchableOpacity style={styles.buttonContainer}
onPress = {()=> {this.onCreate }}
>
<Text style={styles.buttonText}>Create</Text>
</TouchableOpacity>
</View>
</View>
)
}
}
What I actually want is a post method based on the TextInput values entered by the users. More also, the corresponding ID of the selected dropdown value be passed instead of the actual value.
Thank you so much for your assistance.
From what I can read from the code, the problem seems to be in the way you call your onCreate method.
You are doing:
<TouchableOpacity style={styles.buttonContainer} onPress={()=> {this.onCreate }}>
<Text style={styles.buttonText}>Create</Text>
</TouchableOpacity>
Where you should be doing either:
<TouchableOpacity style={styles.buttonContainer} onPress={this.onCreate}>
<Text style={styles.buttonText}>Create</Text>
</TouchableOpacity>
Or:
<TouchableOpacity style={styles.buttonContainer} onPress={() => this.onCreate()}>
<Text style={styles.buttonText}>Create</Text>
</TouchableOpacity>

React-Native how give a method an variable

I'm trying to change a variable in state so I give it to a component as property later on, but i can't seem to change the variable.
constructor(){
super();
this.state = {
dataSource: [],
reading: false,
iName: 'default'
};
this.startRead = this.startRead.bind(this);
}
startRead = ({item}) => {
this.setState({
reading: true,
iName: {item.name} //it doesn't work over here
});
}
renderItem = ({item}) => {
this.setName
return(
<TouchableOpacity style={{flex: 1, flexDirection: 'row', marginBottom: 5}} onPress={this.startRead}>
<Text>{item.name}</Text> // this does work
<Text>{item.desc}</Text>
</TouchableOpacity>
);
}
I called this renderItem function via a FlatList
this.state.reading ?
<ReadScreen iname={this.state.iName}/>
:
<View style={styles.slide}>
<FlatList
data={this.state.dataSource}
renderItem={this.renderItem}
/>
</View>
It gives me an error of
"SyntaxError: App.js: Unexpected token, expected ',' (21,24)"
(21,24) gives the line
iName: {item.name}
What am I doing wrong?
The goal is; when I press a Item of the FlatList, a.k.a. the TouchableOpacity, it renders the ReadScreen that shows, more given information through properties instead of the FlatList.
If it's unclear or need more information, just ask
Thank you for your time.
Replace this line
onPress={this.startRead}
With this line
onPress={() => this.startRead({item})}
Here's the full solution
renderItem = ({item}) => {
this.setName
return(
<TouchableOpacity style={{flex: 1, flexDirection: 'row', marginBottom: 5}} onPress={() => this.startRead({item})}>
<Text>{item.name}</Text> // this does work
<Text>{item.desc}</Text>
</TouchableOpacity>
);
}
Use iName: item.name instead of iName:{item.name}