carlrip / LearnReact17WithTypeScript

MIT License
57 stars 44 forks source link

withLoader error #2

Closed chengzh2008 closed 5 years ago

chengzh2008 commented 5 years ago

Hi, I am reading this book with Chapter 6. I got type error: (below) Type error: Type '{}' is not assignable to type 'P'. TS2322

15 |     </div>
16 |   ) : (

17 | <Component {...props} /> | ^ 18 | ); 19 | export default withLoader;

No sure what is going on.

Thanks for help!

carlrip commented 5 years ago

Thanks for the question - hope you are enjoying the book!

Yes, there is a problem with the withLoader component. We weren't passing all the props to the inner component. Here's what withLoader should look like:

` const withLoader =

( Component: React.ComponentType

): React.SFC<P & IProps> => (props: P & IProps) => props.loading ? (

) : ( <Component {...props} /> ); `

carlrip commented 5 years ago
chengzh2008 commented 5 years ago

Thanks for reply the issue fix. Yes, I really enjoy the book. Thanks producing the book!

hieu-ht commented 5 years ago

You made an amazing book, thank you very much @carlrip. It helps me a lot.

carlrip commented 5 years ago

You made an amazing book, thank you very much @carlrip. It helps me a lot.

Thanks HieuDexZ, glad you liked it.