Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d4886e9

Browse files
committed
move event outside of hook
1 parent 7228257 commit d4886e9

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

‎src/useDataApiHook-example/index.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,30 +63,30 @@ const useDataApi = (initialUrl, initialData) => {
6363
};
6464
}, [url]);
6565

66-
const doGet = (event,url) => {
66+
const doFetch = url => {
6767
setUrl(url);
68-
event.preventDefault();
6968
};
7069

71-
return { ...state, doGet };
70+
return { ...state, doFetch };
7271
};
7372

7473
function App() {
7574
const [query, setQuery] = useState('redux');
76-
const { data, isLoading, isError, doGet } = useDataApi(
75+
const { data, isLoading, isError, doFetch } = useDataApi(
7776
'http://hn.algolia.com/api/v1/search?query=redux',
7877
{ hits: [] },
7978
);
8079

8180
return (
8281
<Fragment>
8382
<form
84-
onSubmit={event =>
85-
doGet(
86-
event,
83+
onSubmit={event => {
84+
doFetch(
8785
`http://hn.algolia.com/api/v1/search?query=${query}`,
88-
)
89-
}
86+
);
87+
88+
event.preventDefault();
89+
}}
9090
>
9191
<input
9292
type="text"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /