-1

I'm getting a few errors after i converted everything in this file to function so i'm able to use hooks.

This error "2020-12-22 is not a function i'm getting when I press the date on the calendarStrip component.

Call Stack. is telling me the problem is on onDateSelected that u can find in the code below. this makes me wonder if i have messed up the useStates since everything works in class component?

CODE WITH USESTATE AND CALENDARSTRIP COMPONENT

const [datesWhitelist] = useState([
    {
      start: moment(),
      end: moment().add(365, "days"),
    },
  ]);
  const [todoList] = useState([]);
  const [markedDate] = useState([]);
  const [currentDate] = useState(
    `${moment().format("YYYY")}-${moment().format("MM")}-${moment().format(
      "DD"
    )}`
  );
  const [selectedTask] = useState(null);
  const [isDateTimePickerVisible] = useState(false);
  const [createEventAsyncRes] = useState("");

<CalendarStrip
        calendarAnimation={{ type: "sequence", duration: 30 }}
        style={{
          height: 150,
          paddingTop: 20,
          paddingBottom: 20,
        }}
        calendarHeaderStyle={{ color: colors.text }}
        dateNumberStyle={{ color: colors.text, paddingTop: 10 }}
        dateNameStyle={{ color: colors.text }}
        highlightDateNumberStyle={{
          color: colors.text,
          backgroundColor: "#990000",
          marginTop: 10,
          height: 35,
          width: 35,
          textAlign: "center",
          borderRadius: 17.5,
          overflow: "hidden",
          paddingTop: 6,
          fontWeight: "400",
          justifyContent: "center",
          alignItems: "center",
        }}
        highlightDateNameStyle={{ color: colors.text }}
        disabledDateNameStyle={{ color: colors.text }}
        disabledDateNumberStyle={{ color: colors.text }}
        datesWhitelist={datesWhitelist}
        iconContainer={{ flex: 0.1 }}
        markedDates={markedDate}
        onDateSelected={(date) => {
          const selectedDate = `${moment(date).format("YYYY")}-${moment(
            date
          ).format("MM")}-${moment(date).format("DD")}`;
          _updateCurrentTask(selectedDate);
          currentDate(selectedDate);
        }}
      />
iLightFPS
  • 63
  • 1
  • 8
  • 1
    `const [value] = useState(something);` Yes, it looks like your maybe not understanding what `useState` does, a `useState` without a setter is a bit meaningless. – Keith Dec 22 '20 at 16:33

1 Answers1

2

This is where the problem comes from:

currentDate(selectedDate);

you are using a string as a function, see how you declare it in state

Viet
  • 12,133
  • 2
  • 15
  • 21