Skip to content

Instantly share code, notes, and snippets.

@kenmori
Last active July 9, 2019 01:16
Show Gist options
  • Save kenmori/2eb384a7c36a8526b1add8dc28e16d8b to your computer and use it in GitHub Desktop.
Save kenmori/2eb384a7c36a8526b1add8dc28e16d8b to your computer and use it in GitHub Desktop.
「JSX props should not use arrow functions」

JSX props should not use arrow functions

react-router-navigation-prompt

./src/components/FormDragAndDropArea/index.tsx
  Line 61:  JSX props should not use arrow functions  react/jsx-no-bind

Error is here!!

 <NavigationPrompt
  when={(currentLocation, nextLocation) => { //here!!
      if(!nextLocation) return false;
      setState((prev) => ({...prev, pathname: nextLocation.pathname}));
      return !nextLocation.pathname.startsWith(currentLocation.pathname) && !!formRows.length && locationState.pathname !== nextLocation.pathname
    }
  }
  >

Fix error with useCallback

 const whenCallback = useCallback((currentLocation, nextLocation) => {
      if(!nextLocation) return false;
      setState((prev) => ({...prev, pathname: nextLocation.pathname}));
      return !nextLocation.pathname.startsWith(currentLocation.pathname) && !!formRows.length && locationState.pathname !== nextLocation.pathname
  }, [formRows.length, locationState.pathname]);
  return (
    <div className={classes.pageContainer}>
      <div className={classes.PartList}>
        <AppSettingsFormPartSwitcher />
        <NavigationPrompt when={whenCallback} > // here!
          {({isActive, onConfirm, onCancel}) => (
          <MoveFormComponentDialog
            isActive={isActive}
            onConfirm={onConfirm}
            onCancel={onCancel}
            dialogId={"comfirmStoreFormRows"}
            line={11}
            index={1}
            length={formRows.length}
            locationState={locationState}
          />)}
        </NavigationPrompt>
      </div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment