Passing Values to new Screen in React native
I have a View that is clickable using touchable opacity which has an item.address and item.price that renders inside.
<TouchableOpacity onPress = {this.onShowHomeDetails.bind()}>
<View style = {{height: 130,width :130,
marginLeft : 20, borderWidth: 0.5, borderColor: '#dddddd'}} >
<View style={{flex: 2}}>
<Image source={{uri : item.imageUrl}}
style={{flex:1, width: null,
height: null, resizeMode: 'cover'}}/>
</View>
<View style={{flex: 1 , paddingLeft: 10,paddingTop: 10}}>
<Text style={{fontWeight:"bold", fontSize :12}}>
{item.address}
</Text>
{this.getIndividualHouseInfo(item.address)}
</View>
<View style={{flex: 1 , paddingLeft: 10}}>
<Text> ${item.price} </Text>
</View>
</View>
</TouchableOpacity>
How do I pass these values through navigation to another screen using the onShowHomeDetails function?
onShowHomeDetails = () => {
this.props.navigation.navigate('HomeDetails');
}
And my home detail component which is the destination screen is
class HomeDetails extends Component{
constructor(props){
super(props);
this.state = {
address : this.props.state.params.address,
};
}
render(){
return(
<View style ={styles.container}>
<Text>Details </Text>
<Text>{this.state.address}</Text>
</View>
);
}
}
reactjs react-native
add a comment |
I have a View that is clickable using touchable opacity which has an item.address and item.price that renders inside.
<TouchableOpacity onPress = {this.onShowHomeDetails.bind()}>
<View style = {{height: 130,width :130,
marginLeft : 20, borderWidth: 0.5, borderColor: '#dddddd'}} >
<View style={{flex: 2}}>
<Image source={{uri : item.imageUrl}}
style={{flex:1, width: null,
height: null, resizeMode: 'cover'}}/>
</View>
<View style={{flex: 1 , paddingLeft: 10,paddingTop: 10}}>
<Text style={{fontWeight:"bold", fontSize :12}}>
{item.address}
</Text>
{this.getIndividualHouseInfo(item.address)}
</View>
<View style={{flex: 1 , paddingLeft: 10}}>
<Text> ${item.price} </Text>
</View>
</View>
</TouchableOpacity>
How do I pass these values through navigation to another screen using the onShowHomeDetails function?
onShowHomeDetails = () => {
this.props.navigation.navigate('HomeDetails');
}
And my home detail component which is the destination screen is
class HomeDetails extends Component{
constructor(props){
super(props);
this.state = {
address : this.props.state.params.address,
};
}
render(){
return(
<View style ={styles.container}>
<Text>Details </Text>
<Text>{this.state.address}</Text>
</View>
);
}
}
reactjs react-native
add a comment |
I have a View that is clickable using touchable opacity which has an item.address and item.price that renders inside.
<TouchableOpacity onPress = {this.onShowHomeDetails.bind()}>
<View style = {{height: 130,width :130,
marginLeft : 20, borderWidth: 0.5, borderColor: '#dddddd'}} >
<View style={{flex: 2}}>
<Image source={{uri : item.imageUrl}}
style={{flex:1, width: null,
height: null, resizeMode: 'cover'}}/>
</View>
<View style={{flex: 1 , paddingLeft: 10,paddingTop: 10}}>
<Text style={{fontWeight:"bold", fontSize :12}}>
{item.address}
</Text>
{this.getIndividualHouseInfo(item.address)}
</View>
<View style={{flex: 1 , paddingLeft: 10}}>
<Text> ${item.price} </Text>
</View>
</View>
</TouchableOpacity>
How do I pass these values through navigation to another screen using the onShowHomeDetails function?
onShowHomeDetails = () => {
this.props.navigation.navigate('HomeDetails');
}
And my home detail component which is the destination screen is
class HomeDetails extends Component{
constructor(props){
super(props);
this.state = {
address : this.props.state.params.address,
};
}
render(){
return(
<View style ={styles.container}>
<Text>Details </Text>
<Text>{this.state.address}</Text>
</View>
);
}
}
reactjs react-native
I have a View that is clickable using touchable opacity which has an item.address and item.price that renders inside.
<TouchableOpacity onPress = {this.onShowHomeDetails.bind()}>
<View style = {{height: 130,width :130,
marginLeft : 20, borderWidth: 0.5, borderColor: '#dddddd'}} >
<View style={{flex: 2}}>
<Image source={{uri : item.imageUrl}}
style={{flex:1, width: null,
height: null, resizeMode: 'cover'}}/>
</View>
<View style={{flex: 1 , paddingLeft: 10,paddingTop: 10}}>
<Text style={{fontWeight:"bold", fontSize :12}}>
{item.address}
</Text>
{this.getIndividualHouseInfo(item.address)}
</View>
<View style={{flex: 1 , paddingLeft: 10}}>
<Text> ${item.price} </Text>
</View>
</View>
</TouchableOpacity>
How do I pass these values through navigation to another screen using the onShowHomeDetails function?
onShowHomeDetails = () => {
this.props.navigation.navigate('HomeDetails');
}
And my home detail component which is the destination screen is
class HomeDetails extends Component{
constructor(props){
super(props);
this.state = {
address : this.props.state.params.address,
};
}
render(){
return(
<View style ={styles.container}>
<Text>Details </Text>
<Text>{this.state.address}</Text>
</View>
);
}
}
reactjs react-native
reactjs react-native
edited Nov 22 '18 at 9:40
varit05
1,640716
1,640716
asked Nov 22 '18 at 3:46
ButtersnipsButtersnips
244
244
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Cool I feel its easy.
Call function:
<TouchableOpacity onPress={this.onShowHomeDetails.bind(this, item)}>
<View style = {{height: 130,width :130,
marginLeft : 20, borderWidth: 0.5,
borderColor: '#dddddd'}} >
<View style={{flex: 2}}>
<Image source={{uri : item.imageUrl}}
style={{flex:1, width: null,
height: null, resizeMode: 'cover'}}
/>
</View>
<View style={{flex: 1 , paddingLeft: 10,paddingTop: 10}}>
<Text style={{fontWeight:"bold" , fontSize :12}}> {item.address} </Text>
{this.getIndividualHouseInfo(item.address)}
</View>
<View style={{flex: 1 , paddingLeft: 10}}>
<Text> ${item.price} </Text>
</View>
</View>
</TouchableOpacity>
Writing function:
onShowHomeDetails = (item) => {
this.props.navigation.navigate('HomeDetails', {item: item});
}
Get params in appropriate screen:
class HomeDetails extends Component{
constructor(props){
super(props);
this.state = {
address : props.navigation.getParam('item', '');
};
}
render(){
return(
<View style ={styles.container}>
<Text>Details </Text>
<Text>{this.state.address}</Text>
</View>
);
}
}
Few important things we should know about passsing value as navigation params.
Passing params and getParams both name should be same.
In getparams method we set empty string(''). Because if value is not
passed, its return empty string
Refer this document it will help you. https://reactnavigation.org/docs/en/params.html
Very close . the function should beonShowHomeDetails = (item) => { this.props.navigation.navigate('HomeDetails' , {address : item.address}); }
. Thanks a ton.
– Buttersnips
Nov 22 '18 at 7:01
add a comment |
You can pass data while navigating to the state.
onShowHomeDetails = () => {
this.props.navigation.navigate('HomeDetails', { home: 'abc'});
// you can pass any type of object in here as well
}
As per the react Navigation doc. The second parameter is the params to pass to destination route.
navigation.navigate({ routeName, params, action, key })
and use it in another component with props.
Option 1:
this.props.navigation.getParam('home')
And if at all home is undefined, option 1 fails but with option 2 it will fallback to bydefaultHome
Option 2:
this.props.navigation.getParam('home', 'bydefaultHome');
Hope this helps!
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423590%2fpassing-values-to-new-screen-in-react-native%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Cool I feel its easy.
Call function:
<TouchableOpacity onPress={this.onShowHomeDetails.bind(this, item)}>
<View style = {{height: 130,width :130,
marginLeft : 20, borderWidth: 0.5,
borderColor: '#dddddd'}} >
<View style={{flex: 2}}>
<Image source={{uri : item.imageUrl}}
style={{flex:1, width: null,
height: null, resizeMode: 'cover'}}
/>
</View>
<View style={{flex: 1 , paddingLeft: 10,paddingTop: 10}}>
<Text style={{fontWeight:"bold" , fontSize :12}}> {item.address} </Text>
{this.getIndividualHouseInfo(item.address)}
</View>
<View style={{flex: 1 , paddingLeft: 10}}>
<Text> ${item.price} </Text>
</View>
</View>
</TouchableOpacity>
Writing function:
onShowHomeDetails = (item) => {
this.props.navigation.navigate('HomeDetails', {item: item});
}
Get params in appropriate screen:
class HomeDetails extends Component{
constructor(props){
super(props);
this.state = {
address : props.navigation.getParam('item', '');
};
}
render(){
return(
<View style ={styles.container}>
<Text>Details </Text>
<Text>{this.state.address}</Text>
</View>
);
}
}
Few important things we should know about passsing value as navigation params.
Passing params and getParams both name should be same.
In getparams method we set empty string(''). Because if value is not
passed, its return empty string
Refer this document it will help you. https://reactnavigation.org/docs/en/params.html
Very close . the function should beonShowHomeDetails = (item) => { this.props.navigation.navigate('HomeDetails' , {address : item.address}); }
. Thanks a ton.
– Buttersnips
Nov 22 '18 at 7:01
add a comment |
Cool I feel its easy.
Call function:
<TouchableOpacity onPress={this.onShowHomeDetails.bind(this, item)}>
<View style = {{height: 130,width :130,
marginLeft : 20, borderWidth: 0.5,
borderColor: '#dddddd'}} >
<View style={{flex: 2}}>
<Image source={{uri : item.imageUrl}}
style={{flex:1, width: null,
height: null, resizeMode: 'cover'}}
/>
</View>
<View style={{flex: 1 , paddingLeft: 10,paddingTop: 10}}>
<Text style={{fontWeight:"bold" , fontSize :12}}> {item.address} </Text>
{this.getIndividualHouseInfo(item.address)}
</View>
<View style={{flex: 1 , paddingLeft: 10}}>
<Text> ${item.price} </Text>
</View>
</View>
</TouchableOpacity>
Writing function:
onShowHomeDetails = (item) => {
this.props.navigation.navigate('HomeDetails', {item: item});
}
Get params in appropriate screen:
class HomeDetails extends Component{
constructor(props){
super(props);
this.state = {
address : props.navigation.getParam('item', '');
};
}
render(){
return(
<View style ={styles.container}>
<Text>Details </Text>
<Text>{this.state.address}</Text>
</View>
);
}
}
Few important things we should know about passsing value as navigation params.
Passing params and getParams both name should be same.
In getparams method we set empty string(''). Because if value is not
passed, its return empty string
Refer this document it will help you. https://reactnavigation.org/docs/en/params.html
Very close . the function should beonShowHomeDetails = (item) => { this.props.navigation.navigate('HomeDetails' , {address : item.address}); }
. Thanks a ton.
– Buttersnips
Nov 22 '18 at 7:01
add a comment |
Cool I feel its easy.
Call function:
<TouchableOpacity onPress={this.onShowHomeDetails.bind(this, item)}>
<View style = {{height: 130,width :130,
marginLeft : 20, borderWidth: 0.5,
borderColor: '#dddddd'}} >
<View style={{flex: 2}}>
<Image source={{uri : item.imageUrl}}
style={{flex:1, width: null,
height: null, resizeMode: 'cover'}}
/>
</View>
<View style={{flex: 1 , paddingLeft: 10,paddingTop: 10}}>
<Text style={{fontWeight:"bold" , fontSize :12}}> {item.address} </Text>
{this.getIndividualHouseInfo(item.address)}
</View>
<View style={{flex: 1 , paddingLeft: 10}}>
<Text> ${item.price} </Text>
</View>
</View>
</TouchableOpacity>
Writing function:
onShowHomeDetails = (item) => {
this.props.navigation.navigate('HomeDetails', {item: item});
}
Get params in appropriate screen:
class HomeDetails extends Component{
constructor(props){
super(props);
this.state = {
address : props.navigation.getParam('item', '');
};
}
render(){
return(
<View style ={styles.container}>
<Text>Details </Text>
<Text>{this.state.address}</Text>
</View>
);
}
}
Few important things we should know about passsing value as navigation params.
Passing params and getParams both name should be same.
In getparams method we set empty string(''). Because if value is not
passed, its return empty string
Refer this document it will help you. https://reactnavigation.org/docs/en/params.html
Cool I feel its easy.
Call function:
<TouchableOpacity onPress={this.onShowHomeDetails.bind(this, item)}>
<View style = {{height: 130,width :130,
marginLeft : 20, borderWidth: 0.5,
borderColor: '#dddddd'}} >
<View style={{flex: 2}}>
<Image source={{uri : item.imageUrl}}
style={{flex:1, width: null,
height: null, resizeMode: 'cover'}}
/>
</View>
<View style={{flex: 1 , paddingLeft: 10,paddingTop: 10}}>
<Text style={{fontWeight:"bold" , fontSize :12}}> {item.address} </Text>
{this.getIndividualHouseInfo(item.address)}
</View>
<View style={{flex: 1 , paddingLeft: 10}}>
<Text> ${item.price} </Text>
</View>
</View>
</TouchableOpacity>
Writing function:
onShowHomeDetails = (item) => {
this.props.navigation.navigate('HomeDetails', {item: item});
}
Get params in appropriate screen:
class HomeDetails extends Component{
constructor(props){
super(props);
this.state = {
address : props.navigation.getParam('item', '');
};
}
render(){
return(
<View style ={styles.container}>
<Text>Details </Text>
<Text>{this.state.address}</Text>
</View>
);
}
}
Few important things we should know about passsing value as navigation params.
Passing params and getParams both name should be same.
In getparams method we set empty string(''). Because if value is not
passed, its return empty string
Refer this document it will help you. https://reactnavigation.org/docs/en/params.html
answered Nov 22 '18 at 5:08
EDISON JEDISON J
24516
24516
Very close . the function should beonShowHomeDetails = (item) => { this.props.navigation.navigate('HomeDetails' , {address : item.address}); }
. Thanks a ton.
– Buttersnips
Nov 22 '18 at 7:01
add a comment |
Very close . the function should beonShowHomeDetails = (item) => { this.props.navigation.navigate('HomeDetails' , {address : item.address}); }
. Thanks a ton.
– Buttersnips
Nov 22 '18 at 7:01
Very close . the function should be
onShowHomeDetails = (item) => { this.props.navigation.navigate('HomeDetails' , {address : item.address}); }
. Thanks a ton.– Buttersnips
Nov 22 '18 at 7:01
Very close . the function should be
onShowHomeDetails = (item) => { this.props.navigation.navigate('HomeDetails' , {address : item.address}); }
. Thanks a ton.– Buttersnips
Nov 22 '18 at 7:01
add a comment |
You can pass data while navigating to the state.
onShowHomeDetails = () => {
this.props.navigation.navigate('HomeDetails', { home: 'abc'});
// you can pass any type of object in here as well
}
As per the react Navigation doc. The second parameter is the params to pass to destination route.
navigation.navigate({ routeName, params, action, key })
and use it in another component with props.
Option 1:
this.props.navigation.getParam('home')
And if at all home is undefined, option 1 fails but with option 2 it will fallback to bydefaultHome
Option 2:
this.props.navigation.getParam('home', 'bydefaultHome');
Hope this helps!
add a comment |
You can pass data while navigating to the state.
onShowHomeDetails = () => {
this.props.navigation.navigate('HomeDetails', { home: 'abc'});
// you can pass any type of object in here as well
}
As per the react Navigation doc. The second parameter is the params to pass to destination route.
navigation.navigate({ routeName, params, action, key })
and use it in another component with props.
Option 1:
this.props.navigation.getParam('home')
And if at all home is undefined, option 1 fails but with option 2 it will fallback to bydefaultHome
Option 2:
this.props.navigation.getParam('home', 'bydefaultHome');
Hope this helps!
add a comment |
You can pass data while navigating to the state.
onShowHomeDetails = () => {
this.props.navigation.navigate('HomeDetails', { home: 'abc'});
// you can pass any type of object in here as well
}
As per the react Navigation doc. The second parameter is the params to pass to destination route.
navigation.navigate({ routeName, params, action, key })
and use it in another component with props.
Option 1:
this.props.navigation.getParam('home')
And if at all home is undefined, option 1 fails but with option 2 it will fallback to bydefaultHome
Option 2:
this.props.navigation.getParam('home', 'bydefaultHome');
Hope this helps!
You can pass data while navigating to the state.
onShowHomeDetails = () => {
this.props.navigation.navigate('HomeDetails', { home: 'abc'});
// you can pass any type of object in here as well
}
As per the react Navigation doc. The second parameter is the params to pass to destination route.
navigation.navigate({ routeName, params, action, key })
and use it in another component with props.
Option 1:
this.props.navigation.getParam('home')
And if at all home is undefined, option 1 fails but with option 2 it will fallback to bydefaultHome
Option 2:
this.props.navigation.getParam('home', 'bydefaultHome');
Hope this helps!
edited Nov 22 '18 at 4:16
answered Nov 22 '18 at 4:11
varit05varit05
1,640716
1,640716
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423590%2fpassing-values-to-new-screen-in-react-native%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown