diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..4cebcff Binary files /dev/null and b/.DS_Store differ diff --git a/Components-and-Hooks/HOC-Props-and-Custom-Hooks.md b/Components-and-Hooks/HOC-Props-and-Custom-Hooks.md index dc12c7a..46400b2 100644 --- a/Components-and-Hooks/HOC-Props-and-Custom-Hooks.md +++ b/Components-and-Hooks/HOC-Props-and-Custom-Hooks.md @@ -35,19 +35,19 @@ So here are some codes for basic understanding HOC. ```javascript function ParentElement(props) { return ( -
-
Hi
- {props.children} -
+ + Hi + {props.children} + ); } function ChildComponentOne() { - return
Child
; + return Child 1; } function ChildComponentTwo() { - return
Child
; + return Child 2; } export default function App() { @@ -73,20 +73,20 @@ So here are some codes for basic understanding. ```javascript function ParentElement(props) { return ( -
-
Hi
- {props.ChildComponentOne} - {props.ChildComponentTwo} -
+ + Hi + {props.ChildComponentOne} + {props.ChildComponentTwo} + ); } function ChildComponentOne() { - return
Child
; + return Child 1; } function ChildComponentTwo() { - return
Child
; + return Child 2; } export default function App() { @@ -106,36 +106,36 @@ In the above code props rendering occurred by **_props.ChildComponentOne_** & ** Besides regular JSX components, we can pass functions as children to React components. This function is available to us through the children prop, which is technically also a render prop. ```javascript - function ParentElement(props) { - const [stateValue, setStateValue] = useState(“Child”); - return ( -
-
Parent
- {props.children(stateValue)} -
- ); - } +function ParentElement(props) { + const [stateValue, setStateValue] = useState(“Child”); + return ( + + Parent + {props.children(stateValue)} + + ); +} - function ChildComponentOne(props) { - return
{props.value}
; - } +function ChildComponentOne(props) { + return {props.value}; +} - function ChildComponentTwo(props) { - return
{props.value}
; - } +function ChildComponentTwo(props) { + return {props.value}; +} - export default function App(){ - return ( - - {(data) => ( - <> - - - - )} - - ) - } +export default function App(){ + return ( + + {(data) => ( + <> + + + + )} + + ) +} ``` In the above code **_props.children(stateValue)_** created props rendering. @@ -149,21 +149,25 @@ A **Higher Order Component (HOC)** is a component that receives another componen Say that we always wanted to add a certain styling to multiple components in our application. Instead of creating a style object locally each time, we can simply create a HOC that adds the style objects to the component that we pass to it. ```javascript - function withStyles(Component) { - return props => { - const style = { padding: '0.2rem', margin: '1rem' } - return - } +function withStyles(Component) { + return props => { + const style = { + padding: '0.2rem', + margin: '1rem' } - const Button = () = - const Text = () =>

Hello World!

+ return + } +} - const StyledButton = withStyles(Button) - const StyledText = withStyles(Text) +const MyButton = () = - - ); - } - } + render() { + return ( + + + - - ); - } + return ( + + setMessage(e.target.value)} + type="text" + placeholder="Type something..." + /> + - const StyledButton = withStyles(Button) + return + } +} + +const MyButton = () = - const StyledButton = withStyles(Button) + return + } +} + +const MyButton = () =