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) => {
63
63
} ;
64
64
} , [ url ] ) ;
65
65
66
- const doGet = ( event , url ) => {
66
+ const doFetch = url => {
67
67
setUrl ( url ) ;
68
- event . preventDefault ( ) ;
69
68
} ;
70
69
71
- return { ...state , doGet } ;
70
+ return { ...state , doFetch } ;
72
71
} ;
73
72
74
73
function App ( ) {
75
74
const [ query , setQuery ] = useState ( 'redux' ) ;
76
- const { data, isLoading, isError, doGet } = useDataApi (
75
+ const { data, isLoading, isError, doFetch } = useDataApi (
77
76
'http://hn.algolia.com/api/v1/search?query=redux' ,
78
77
{ hits : [ ] } ,
79
78
) ;
80
79
81
80
return (
82
81
< Fragment >
83
82
< form
84
- onSubmit = { event =>
85
- doGet (
86
- event ,
83
+ onSubmit = { event => {
84
+ doFetch (
87
85
`http://hn.algolia.com/api/v1/search?query=${ query } ` ,
88
- )
89
- }
86
+ ) ;
87
+
88
+ event . preventDefault ( ) ;
89
+ } }
90
90
>
91
91
< input
92
92
type = "text"
You can’t perform that action at this time.
0 commit comments