Last active
October 22, 2022 08:32
-
-
Save yuvalbl/a1b073ab4430117bf9e4bbb9d24bd71e to your computer and use it in GitHub Desktop.
React and the Missing Children
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ErrorMessage | |
import React, {FC} from 'react'; | |
const ErrorMessage: FC = () => { | |
const { uiStore } = useStores(); | |
if(!uiStore.error) { | |
return null; | |
} | |
return <div className="error-message">{uiStore.error}</div> | |
} | |
// usage | |
<ErrorMessage/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {FC} from 'react'; | |
interface Props {} // no need to define children | |
const Message: FC<Props> = ({ children }) => ( | |
<div>{children}</div> | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {FC, ReactNode} from 'react'; | |
interface Props { | |
children: ReactNode; | |
} | |
const Message: FC<Props> = ({ children }) => ( | |
<div>{children}</div> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use like this:
https://gist.github.com/yuvalbl/a1b073ab4430117bf9e4bbb9d24bd71e?file=Solution.tsx