Skip to content

Instantly share code, notes, and snippets.

@gHashTag
Created July 30, 2019 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gHashTag/fe0c4783143b2003c09e87e8bd2810a5 to your computer and use it in GitHub Desktop.
Save gHashTag/fe0c4783143b2003c09e87e8bd2810a5 to your computer and use it in GitHub Desktop.
CurrentIndex - React Hook
const App = () => {
const { container } = styles
const [currentIndex, setCurrentIndex] = useState(0)
const array = [{ title: "Today" }, { title: "Week" }, { title: "Month" }]
return (
<View style={container}>
<Text>{${currentIndex}}</Text>
{array.map(({ title }, i) => (
<TouchableOpacity key={title} onPress={() => setCurrentIndex(i)}>
<Text>{title}</Text>
</TouchableOpacity>
))}
</View>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment