Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Dynamic state example
import * as React from 'react';
import * as ReactNative from 'react-native';
import connect from 'react-redux'
class MyComponent extends React.Component {
constructor(props) {
// Assign state based on props
// A contrived example:
if (props.count > 0) {
this.state = {
count: props.count,
hasCount: true
}
} else {
this.state = {
count: 0,
hasCount: false
}
}
}
render() {
return (
<ReactNative.View>
{this.state.hasCount &&
<ReactNative.Text>{this.state.count}</ReactNative.Text>
}
</ReactNative.View>
);
}
}
export default connect(
({ count }) => count
)(MyComponent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.