File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed
src/useDataApiHook-example Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff 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
7473function 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"
You can’t perform that action at this time.
0 commit comments