jeudi 3 octobre 2019

React-Native. If-Else Operator does not work

can somebody help me with my problem? I want the to start when this.state.counter reaches 0. I cant see where my Problem is. The Confetti works when I use it without the IF-Else Operator. Thank you for your time :)

import React from "react";
    import {
      StyleSheet,
      Button,
      View,

    } from "react-native";

    import Confetti from 'react-native-confetti';


    export default class App extends React.Component {

      state = {
        counter: 2
      };

      componentDidMount() {
        if (this._confettiView) {
          this._confettiView.startConfetti();
        }
      }

      render() {
        return (
          <View style={styles.container}>
            {this.state.counter == 0 ? <Confetti ref={(node) => this._confettiView = node} /> : null}
            <Button
            title="Press"
              onPress={() => this.setState({ counter: this.state.counter - 1 })}>
            </Button>
          </View>
        );
      }
    }
    const styles = StyleSheet.create({
      container: {
        flex: 1,
        backgroundColor: "#87CEEB"
      }
    });

Aucun commentaire:

Enregistrer un commentaire