-1

The error appears in the line where I define onIncrease and onDecrease. Following a class on React-native I coded the same code as it was in class but I get this error. Could anybody please help..

import React, {useState} from 'react';
import {View, Text, StyleSheet} from 'react-native';
import ColorCounter from '../components/ColorCounter';

const COLOR_INCREMENT = 15;

const SquareScreen = () => {
  const [red, setRed] = useState(0);
  const [green, setGreen] = useState(0);
  const [blue, setBlue] = useState(0);

  const setColor = (color, change) => {
    switch (color) {
      case 'red':
        red + change > 255 ||  red + change < 0 ? null: setRed(red + change);
        return;
      case 'green':
        green + change > 255 ||  green + change < 0 ? null: setGreen(green + change);
        return;
      case 'blue':
        blue + change > 255 ||  blue + change < 0 ? null: setBlue(blue + change);
        return;
      default:
        return;
    }
  };

  return (
    <View>
      <ColorCounter onIncrease{() => setColor('red', COLOR_INCREMENT)} onDecrease{() => setColor('red', -1 * COLOR_INCREMENT)} color="Red"/>
      <ColorCounter
        onIncrease{() => setColor('blue', COLOR_INCREMENT)}
        onDecrease{() => setColor('blue', -1 * COLOR_INCREMENT)}
        color="Blue"
      />
      <ColorCounter
        onIncrease{() => setColor('green', COLOR_INCREMENT)}
        onDecrease{() => setColor('green', -1 * COLOR_INCREMENT)}
        color="Green"/>
    </View>
  );
};

const styles = StyleSheet.create({});

export default SquareScreen;
  • I am just a beginner and following an online class thus not comfortable with the syntax. Anyway thank you @Lenoarod – Ferda Ömeri Nov 03 '19 at 18:08

1 Answers1

1

Maybe you're missing the affectation mark = ?

onIncrease = {() => setColor('blue', COLOR_INCREMENT)}
onDecrease = {() => setColor('blue', -1 * COLOR_INCREMENT)}
whd.nsr
  • 684
  • 6
  • 12
  • Thank you so much, it worked. Since I am a beginner I am not still comfortable with it. You really helped me @whd.nsr – Ferda Ömeri Nov 03 '19 at 14:07