mirror of
https://github.com/teamhanko/hanko.git
synced 2025-10-29 23:59:46 +08:00
fix(examples): prevent default form submit when adding a todo
This commit is contained in:
committed by
Björn Müller
parent
ec1ee87099
commit
bfcf4b941a
@ -1,7 +1,7 @@
|
|||||||
|
import React, {useCallback, useEffect, useMemo, useState} from "react";
|
||||||
import {NextPage} from "next";
|
import {NextPage} from "next";
|
||||||
import {useRouter} from "next/router";
|
import {useRouter} from "next/router";
|
||||||
import {TodoClient, TodoList} from "../util/TodoClient";
|
import {TodoClient, TodoList} from "../util/TodoClient";
|
||||||
import {useCallback, useEffect, useMemo, useState} from "react";
|
|
||||||
import styles from "../styles/Todo.module.css";
|
import styles from "../styles/Todo.module.css";
|
||||||
|
|
||||||
const api = process.env.NEXT_PUBLIC_BACKEND!;
|
const api = process.env.NEXT_PUBLIC_BACKEND!;
|
||||||
@ -14,7 +14,8 @@ const Todo: NextPage = () => {
|
|||||||
const [description, setDescription] = useState<string>("");
|
const [description, setDescription] = useState<string>("");
|
||||||
const [error, setError] = useState<Error | null>(null);
|
const [error, setError] = useState<Error | null>(null);
|
||||||
|
|
||||||
const addTodo = () => {
|
const addTodo = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||||
|
event.preventDefault();
|
||||||
const entry = {description, checked: false};
|
const entry = {description, checked: false};
|
||||||
|
|
||||||
client.addTodo(entry).then((res) => {
|
client.addTodo(entry).then((res) => {
|
||||||
|
|||||||
@ -12,7 +12,8 @@ function Todo() {
|
|||||||
const [error, setError] = useState<Error | null>(null);
|
const [error, setError] = useState<Error | null>(null);
|
||||||
const client = useMemo(() => new TodoClient(api), []);
|
const client = useMemo(() => new TodoClient(api), []);
|
||||||
|
|
||||||
const addTodo = () => {
|
const addTodo = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||||
|
event.preventDefault();
|
||||||
const entry = {description, checked: false};
|
const entry = {description, checked: false};
|
||||||
|
|
||||||
client.addTodo(entry).then((res) => {
|
client.addTodo(entry).then((res) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user