score:0

1.you are not providing a complete component example so we know if there are conflicts, if there's a different setisopen that overwrites the one in this component or any other bugs that might be caused by your logic. 2.you are not specifying the relationship of oncalendarselect and this component. are you passing the function as a prop? are you extracting it from context? is it defined inside the component? 3. do you have another setisopen in the app that could overwrite the one here?

however. i think you should pass the setisopen function to your oncalendarselect function. as in the example below. if this does not work please provide the full component code and the code of the component where oncalendarselect is.

const [isopen, setisopen] = usestate(false);
     {isopen && (
                <drop
                  overflow="unset"
                  align={{ right: "left", top: "bottom", bottom: "bottom" }}
                  style={{ overflowy: "scroll" }}
                  target={targetref.current}
                  onclickoutside={() => setisopen(false)}
                  onesc={() => setisopen(false)}
                >
                  <calendar
                    date={
                      value
                        ? moment(value)
                            .format()
                            .split("t")[0]
                        : null
                    }
                    onselect={evt => {
                      oncalendarselect(evt.tostring(), setisopen);
                    }}
                    size="small"
                    {...(calendarpassedprops as calendarprops)}
                  />
                </drop>
              )}

useeffect(() => {
  console.log("useeffect ",isopen)
}, [isopen])


const oncalendarselect = (v: string, setisopen: any) => {
  console.log(isopen) //always showing true
  setisopen(false)
  const date = moment(v)
    .format()
    .split("t")[0]
    .replaceall("-", "/");
  try {
    setvalue(date);
    if (onchange) {
      onchange(date);
    }
  } catch (e) {
    // prevent invalid dates
  }
};

score:0

fixed by adding a evt.stoppropagation

<drop
              overflow="unset"
              align={{ right: "left", top: "bottom", bottom: "bottom" }}
              style={{ overflowy: "scroll" }}
              target={targetref.current}
              onclickoutside={() => setisopen(false)}
              onclick={(evt: react.mouseevent) => {
                evt.stoppropagation();
              }}
            >

Related Query

More Query from same tag