How to use the react-router-dom.useHistory function in react-router-dom

To help you get started, we’ve selected a few react-router-dom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CLOSER-Cohorts / archivist / react / src / pages / InstrumentBuildQuestionItems.js View on Github external
const InstrumentBuildQuestionItems = (props) => {
  let history = useHistory();

  const dispatch = useDispatch()
  const classes = useStyles();
  const questionItemId = get(props, "match.params.questionItemId", null);

  const instrumentId = get(props, "match.params.instrument_id", "")
  const questionItems = useSelector(state => get(state.questionItems, instrumentId, {}));
  const selectedQuestion = get(questionItems, questionItemId, {used_by: []})

  useEffect(() => {
    dispatch(QuestionItems.all(instrumentId));
    // eslint-disable-next-line react-hooks/exhaustive-deps
  },[]);

  const QuestionItem = (props) => {
    const {label, value, id} = props
github rsnay / wadayano / client / src / components / instructor / QuestionImporter.js View on Github external
const QuestionImporter = () => {
  const { quizId } = useParams();
  const history = useHistory();

  const [questionIds, setQuestionIds] = useState([]);
  const [isSaving, setIsSaving] = useState(false);

  const { loading, error, data } = useQuery(QUIZ_QUERY, { variables: { id: quizId } });
  const [importQuestionsMutation] = useMutation(IMPORT_QUESTIONS);

  const importQuestions = async () => {
    setIsSaving(true);
    try {
      // Send the mutation
      const result = await importQuestionsMutation({
        variables: { quizId, questionIds },
      });
      // Handle errors
      if (result.errors && result.errors.length > 0) {
github pdxphilippmac / patchfox / client / src / components / HomeScreenLogin.js View on Github external
export default function HomescreenPasswordInput(props) {
  const [email, setEmail] = useState("");
  const [password, setPassword] = useState("");
  let history = useHistory();

  function handleSubmit(event) {
    event.preventDefault();
  }

  function validateForm() {
    return email.length > 0 && password.length > 0;
  }

  function handleDirectToPath() {
    history.push("/News");
  }

  return (
    
      <form></form>
github ansible / awx / awx / ui_next / src / screens / Organization / OrganizationEdit / OrganizationEdit.jsx View on Github external
function OrganizationEdit({ organization }) {
  const detailsUrl = `/organizations/${organization.id}/details`;
  const history = useHistory();
  const [formError, setFormError] = useState(null);

  const handleSubmit = async (
    values,
    groupsToAssociate,
    groupsToDisassociate
  ) => {
    try {
      await OrganizationsAPI.update(organization.id, values);
      await Promise.all(
        groupsToAssociate.map(id =>
          OrganizationsAPI.associateInstanceGroup(organization.id, id)
        )
      );
      await Promise.all(
        groupsToDisassociate.map(id =>
github argoproj / argo-rollouts / ui / src / app / components / rollouts-list / rollouts-list.tsx View on Github external
};

    useKeybinding(Key.RIGHT, () => nav(1));
    useKeybinding(Key.LEFT, () => nav(-1));
    useKeybinding(Key.ESCAPE, () => {
        reset();
        if (searchString && searchString !== '') {
            setSearchString('');
            return true;
        } else {
            return false;
        }
    });

    const rolloutNames = useRolloutNames(rollouts);
    const history = useHistory();

    useKeybinding(Key.SLASH, () => {
        if (!searchString) {
            if (searchInput.inputref.current) {
                searchInput.inputref.current.focus();
            }
            return true;
        }
        return false;
    });

    useKeybinding(Key.ENTER, () => {
        if (pos > -1) {
            history.push(`/rollout/${filteredRollouts[pos].objectMeta?.name}`);
            return true;
        }
github ZupIT / horusec / horusec-manager / src / pages / External / Auth / LDAP / index.tsx View on Github external
function LDAPAuth() {
  const { t } = useTranslation();
  const { loginInProgress, login } = useAuth();
  const history = useHistory();

  const [username, setUsername] = useState({
    value: '',
    isValid: false,
  });
  const [password, setPassword] = useState({
    value: '',
    isValid: false,
  });

  const handleSubmit = (event: FormEvent) =&gt; {
    event.preventDefault();

    if (username.isValid &amp;&amp; password.isValid) {
      login({ username: username.value, password: password.value }).then(() =&gt; {
        history.push('/home');
github navtrack / navtrack / Navtrack.Core / ClientApp / src / components / framework / layouts / admin / AdminNavbar.tsx View on Github external
export default function AdminNavbar() {
  const { appContext } = useContext(AppContext);
  const history = useHistory();
  const [menuIsVisible, showMenu] = useClickOutside();

  const handleLogout = () =&gt; {
    AuthenticationService.clearAuthenticationInfo();

    history.push("/");
  };

  return (
    <nav>
      <h1>
        
      </h1>
      <div>
        <div>
          <button color="primary"> history.push("/assets/add")} size="xs"&gt;</button></div></div></nav>
github alexieyizhe / intern.plus / src / pages / reviews / components / ReviewModal.tsx View on Github external
const ReviewModal: React.FC = () => {
  /**
   * If there is no background (usually when user navigates directly
   * to a review) then by default, show it on the landing page by
   * adding the state manually to set background page to landing.
   */
  const location = useLocation();
  const history = useHistory();
  useEffect(() => {
    const noBackgroundPageSet = !(location.state && location.state.background);
    if (noBackgroundPageSet) {
      const defaultBackgroundPage = {
        pathname: RouteName.LANDING,
      };
      const newLocation = {
        ...location,
        state: {
          background: defaultBackgroundPage,
        },
      };

      history.replace(defaultBackgroundPage);
      history.push(newLocation);
    }
github ipti / br.tag / registration / src / containers / Login / index.js View on Github external
const SignIn = () => {
  const [isValid, setValid] = useState(true);
  let history = useHistory();
  const onSubmit = values => {
    api.post("login", values).then(function(response) {
      if (response && !("error" in response.data)) {
        login(response.data.data.access_token);
        history.push("/");
      } else {
        setValid(false);
      }
    });
  };

  const validationSchema = Yup.object().shape({
    username: Yup.string().required("Username é obrigatório!"),
    password: Yup.string()
      .min(6, "Senha deve ter no mínimo 6 caracteres")
      .required("Senha é obrigatória!")