File tree Expand file tree Collapse file tree 2 files changed +16
-15
lines changed
Expand file tree Collapse file tree 2 files changed +16
-15
lines changed Original file line number Diff line number Diff line change @@ -155,14 +155,12 @@ class App extends Component {
155155 />
156156 }
157157 < div className = "interactions" >
158- { isLoading
159- ? < Loading />
160- : < Button
161- onClick = { ( ) => this . fetchSearchTopStories ( searchKey , page + 1 ) }
162- >
163- More
164- </ Button >
165- }
158+ < ButtonWithLoading
159+ isLoading = { isLoading }
160+ onClick = { ( ) => this . fetchSearchTopStories ( searchKey , page + 1 ) }
161+ >
162+ More
163+ </ ButtonWithLoading >
166164 </ div >
167165 </ div >
168166 ) ;
@@ -231,6 +229,13 @@ const Button = ({
231229const Loading = ( ) =>
232230 < div > Loading ...</ div >
233231
232+ const withLoading = ( Component ) => ( { isLoading, ...rest } ) =>
233+ isLoading
234+ ? < Loading />
235+ : < Component { ...rest } />
236+
237+ const ButtonWithLoading = withLoading ( Button ) ;
238+
234239export default App ;
235240
236241export {
Original file line number Diff line number Diff line change @@ -28,13 +28,9 @@ exports[`App has a valid snapshot 1`] = `
2828 <div
2929 className = " interactions"
3030 >
31- <button
32- className = " "
33- onClick = { [Function ]}
34- type = " button"
35- >
36- More
37- </button >
31+ <div >
32+ Loading ...
33+ </div >
3834 </div >
3935</div >
4036` ;
You can’t perform that action at this time.
0 commit comments