Not sure how to render this component with click of a button in react-native

anushka

Following is a barChart function. It returns a barChart in the screen-

const barCharts = () => {
  const fill = 'rgb(134, 65, 244)'
  const data = [50, 10, 40, 95, -4, -24, null, 85, undefined, 0, 35, 53, -53, 24, 50, -20, -80]
  return (
    <View style={styles.sectionContainer}>
      <BarChart style={{ height: 200 }} data={data} svg={{ fill }} contentInset={{ top: 30, bottom: 30 }}>
        <Grid />
      </BarChart>
    </View>
  );
};

I want this barChart component to render upon click of a button. My current environment is react-native ios. How would I accomplish rendering this upon click of a button in App.js?

Łukasz Karczewski
const BarCharts = () => {
  const fill = 'rgb(134, 65, 244)'
  const data = [50, 10, 40, 95, -4, -24, null, 85, undefined, 0, 35, 53, -53, 24, 50, -20, -80]
  return (
    <View style={styles.sectionContainer}>
      <BarChart style={{ height: 200 }} data={data} svg={{ fill }} contentInset={{ top: 30, bottom: 30 }}>
        <Grid />
      </BarChart>
    </View>
  );
};

const OtherComponent = () => {
    const [clicked, setClicked] = React.useState(false);
    return <View>
        <Button onClick={() => setClicked(!clicked)}>Click me</Button>
        {clicked && <BarCharts />}
    </View>
}

Something like this, may not be 100% react-native compliant but you should be able to adjust it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I render a component when a button is clicked in React Native

From Dev

Render a component onPress(TouchableOpacity/Button) in React Native

From Dev

React-native, render a button click dynamically

From Dev

React native button click render different components

From Dev

React-native, render a button click dynamically

From Dev

How to render component with ajax in react native?

From Dev

How to print React component on click of a button?

From Dev

How to change screen in react native with react-navigation on click of a button?

From Dev

react JS render a component after a click

From Dev

How to validate email and password on click of submit button in React native?

From Dev

React native:how to get Text value on a button click?

From Dev

How to dynamically Load API Data on a button Click in React Native

From Dev

react native render another component in main

From Dev

How to animate a React component on render?

From Dev

React: how to render data into a component?

From Dev

how to render objects in react native?

From Dev

React scroll component horizontally on button click

From Dev

React add and remove a component on button click

From Dev

Why does react native not supply a button component?

From Dev

React Native custom toggle button component

From Dev

react native : How to fix the error - Passing an inline function will cause the component state to be lost on re-render?

From Dev

react native : How to fix the error - Passing an inline function will cause the component state to be lost on re-render?

From Java

Not sure how to convert this React hooks component into a functional component

From Dev

React native button click move to another screen

From Dev

How do I export Facebook Messenger "Send" Button as a Native UI Component in React Native?

From Dev

How to navigate to different screen on button click in react-native android app using react-navigation

From Dev

react native route flux re-render component on stack pop

From Dev

React Native FlatList - Calling A Function In The Render Method Which Returns A Component

From Dev

How to render a personalized button component on the same line with button elements

Related Related

  1. 1

    How do I render a component when a button is clicked in React Native

  2. 2

    Render a component onPress(TouchableOpacity/Button) in React Native

  3. 3

    React-native, render a button click dynamically

  4. 4

    React native button click render different components

  5. 5

    React-native, render a button click dynamically

  6. 6

    How to render component with ajax in react native?

  7. 7

    How to print React component on click of a button?

  8. 8

    How to change screen in react native with react-navigation on click of a button?

  9. 9

    react JS render a component after a click

  10. 10

    How to validate email and password on click of submit button in React native?

  11. 11

    React native:how to get Text value on a button click?

  12. 12

    How to dynamically Load API Data on a button Click in React Native

  13. 13

    react native render another component in main

  14. 14

    How to animate a React component on render?

  15. 15

    React: how to render data into a component?

  16. 16

    how to render objects in react native?

  17. 17

    React scroll component horizontally on button click

  18. 18

    React add and remove a component on button click

  19. 19

    Why does react native not supply a button component?

  20. 20

    React Native custom toggle button component

  21. 21

    react native : How to fix the error - Passing an inline function will cause the component state to be lost on re-render?

  22. 22

    react native : How to fix the error - Passing an inline function will cause the component state to be lost on re-render?

  23. 23

    Not sure how to convert this React hooks component into a functional component

  24. 24

    React native button click move to another screen

  25. 25

    How do I export Facebook Messenger "Send" Button as a Native UI Component in React Native?

  26. 26

    How to navigate to different screen on button click in react-native android app using react-navigation

  27. 27

    react native route flux re-render component on stack pop

  28. 28

    React Native FlatList - Calling A Function In The Render Method Which Returns A Component

  29. 29

    How to render a personalized button component on the same line with button elements

HotTag

Archive