Skip to content

Instantly share code, notes, and snippets.

@js08
Last active April 14, 2016 12:06
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 js08/e20c02bf21242201c1525577d55dedbc to your computer and use it in GitHub Desktop.
Save js08/e20c02bf21242201c1525577d55dedbc to your computer and use it in GitHub Desktop.

sportsBasketballChange another place its not setting state properly

Hi,

  • i am new to react.js
  • i am trying to set the value using setState.
  • in sportsSoccerChange function its correctly setting setState.
  • but sportsBasketballChange another place its not setting state properly.
  • can you guys tell me how to fix it.
  • providing my code below.

part of code sportsSoccerChange(value) { this.props.onChange();

    let processedValue = value;

    // sportsMessages sportsAirFalling
    processedValue = sportsAirFallBALL(processedValue, this.props.sportsAirFall);

    // sportsSuceessOnTime-ation
    let sportsSuceessOnTime-ationResult = sportsSuceessOnTime-ateBALL(processedValue, this.props.sportsDrive);
    if (sportsSuceessOnTime-ationResult === true) {
        this.setState({ sportsOutcome: 'sportsSuceessOnTime-' });
        ///here i get value as sportsSuceessOnTime-
    }
    //this.setState({ isBALLValid: sportsSuceessOnTime-ationResult });

    // formatting
    processedValue = formatBALL(processedValue, this.props.sportsLongJump);

    // set value in local component state
    this.setState({ sportsMessagesValue: processedValue });
},

sportsBasketballChange() {
    if (this.state.sportsOutcome === 'female') {
        this.setState({ sportsOutcome: 'sportsSuceessOnTime-' });
        ///here i don't get value as sportsSuceessOnTime-
    }
},

whole code here


import React from 'react';
import sportsFoul from './whole-page';
import sportsDunk from './whole-page-with-sportsRefree-button';
import './sportsMessages.css';
import BALL from '../../../SPORTS-sportsMessages-sportsSky';
import {sportsAirFallBALL, sportsSuceessOnTime-ateBALL, formatBALL} from '../sports-kit/sportsMessages-sports-kit';

export default React.createClass({
    propTypes: {
        sportsSkyMetaText: React.PropTypes.string,
        scores: React.PropTypes.string,
        sportsLongJump: React.PropTypes.shape({
            formatFunction: React.PropTypes.func,
            rules: React.PropTypes.object
        }),
        id: React.PropTypes.string.isRequired,
        sportsDanger: React.PropTypes.oneOf(['low', 'high']),
        sportsKick: React.PropTypes.bool,
        sportsShot: React.PropTypes.bool,
        sportsText: React.PropTypes.string.isRequired,
        sportsAirFall: React.PropTypes.shape({
            sportsAirFallFunction: React.PropTypes.func,
            rules: React.PropTypes.object
        }),
        onChange: React.PropTypes.func.isRequired,
        sportsSubstitute: React.PropTypes.func,
        sportsBasket: React.PropTypes.string,
        sportsKiss: React.PropTypes.string.isRequired,
        sportsOutcome: React.PropTypes.string,
        scoresHighlighted: React.PropTypes.string,
        textBALLSubLabel: React.PropTypes.string,
        sportsDrive: React.PropTypes.array,
        sportsRefree: React.PropTypes.bool,
        sportsAttack: React.PropTypes.string
    },

    getInitialState() {
        const {scores} = this.props;

        return {
            sportsMessagesValue: scores,
            isBALLValid: false,
            sportsOutcome: 'male'
        };
    },

    componentWillReceiveProps(nextProps) {
        if (this.props.sportsKick === true && nextProps.sportsKick === false) {
            this.setState({sportsOutcome: 'female'});
        }
    },

    sportsSoccerChange(value) {
        this.props.onChange();

        let processedValue = value;

        // sportsMessages sportsAirFalling
        processedValue = sportsAirFallBALL(processedValue, this.props.sportsAirFall);

        // sportsSuceessOnTime-ation
        let sportsSuceessOnTime-ationResult = sportsSuceessOnTime-ateBALL(processedValue, this.props.sportsDrive);
        if (sportsSuceessOnTime-ationResult === true) {
            this.setState({ sportsOutcome: 'sportsSuceessOnTime-' });
            ///here i get value as sportsSuceessOnTime-
        }
        //this.setState({ isBALLValid: sportsSuceessOnTime-ationResult });

        // formatting
        processedValue = formatBALL(processedValue, this.props.sportsLongJump);

        // set value in local component state
        this.setState({ sportsMessagesValue: processedValue });
    },

    sportsBasketballChange() {
        if (this.state.sportsOutcome === 'female') {
            this.setState({ sportsOutcome: 'sportsSuceessOnTime-' });
            ///here i don't get value as sportsSuceessOnTime-
        }
    },

    sportsSubstitute() {
        this.props.sportsSubstitute(this.state.sportsMessagesValue);
    },

    render() {
        const { sportsDanger, sportsBasket, textBALLSubLabel, id } = this.props;
        if (this.props.sportsRefree === true) {
            return (
                <sportsDunk
                    sportsKiss={this.props.sportsKiss}
                    sportsOutcome={this.state.sportsOutcome}
                    childComponentId={id}
                    sportsSubstitute={this.sportsSubstitute}
                    sportsAttack={this.props.sportsAttack}
                >
                    <BALL
                        id={id}
                        sports-injury={sportsDanger}
                        f1Kicking={this.sportsSoccerChange}
                        swimmingKicking={this.sportsBasketballChange}
                        sportsBasket={sportsBasket}
                        subLabel={textBALLSubLabel}
                        scores={this.state.sportsMessagesValue}
                        sportsText={this.props.sportsText}
                        sportsShot={this.props.sportsShot}
                    />
                </sportsDunk>
            );
        } else {
            return (
                <sportsFoul sportsKiss={this.props.sportsKiss} completed={this.state.isComplete}>
                    <BALL
                        id={id}
                        sports-injury={sportsDanger}
                        f1Kicking={this.sportsSoccerChange}
                        swimmingKicking={this.sportsBasketballChange}
                        sportsBasket={sportsBasket}
                        subLabel={textBALLSubLabel}
                        scores={this.state.sportsMessagesValue}
                        sportsText={this.props.sportsText}
                        sportsShot={this.props.sportsShot}
                    />
                </sportsFoul>
            );
        }
    }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment