File tree Expand file tree Collapse file tree 4 files changed +89
-7
lines changed Expand file tree Collapse file tree 4 files changed +89
-7
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ Useful React Hooks
1818* [ ` useEventListener ` ] ( #event-hook ) - Hook for binding to an hander to DOM event
1919* [ ` useFavicon ` ] ( #favicon-hook ) - Hook to set a favicon
2020* [ ` useTitle ` ] ( #title-hook ) - Hook to manipulate the page title
21+ * [ ` useMetaTag ` ] ( #meta-tag-hook ) - Hook to manipulate meta tags
2122* [ ` useScript ` ] ( #script-hook ) - Hook to add JavaScript to the page
2223* [ ` useStyles ` ] ( #style-hook ) - Hook to add CSS to the page
2324* [ ` useStyleSheet ` ] ( #stylesheet-hook ) - Hook to add a css file to the page
@@ -281,6 +282,26 @@ export default () => {
281282}
282283` ` `
283284
285+ ## Meta Tag Hook
286+
287+ ` ` ` jsx
288+ import React , { useEffect } from ' react'
289+ import { useMetaTag } from ' @brightleaf/react-hooks'
290+
291+ export default () => {
292+ const [metaValue , setMetaValue ] = useMetaTag (' description' , ' Brightleaf JS React Hooks' )
293+ // <meta name="description" content="Brightleaf JS React Hooks">
294+ setMetaValue (' Awesome React Hooks from Brightleaf JS' )
295+ // <meta name="description" content="Awesome React Hooks from Brightleaf JS">
296+ useMetaTag (
297+ ' og:title' ,
298+ ' Brightleaf JS React Hooks' ,
299+ ' property'
300+ )
301+ // <meta property="og:title" content="Brightleaf JS React Hooks">
302+ return < div> The Page< / div>
303+ }
304+ ` ` `
284305# NES Hook
285306
286307Client hook for connecting to an [NES](https://github.com/hapijs/nes) instance
Original file line number Diff line number Diff line change 11import React , { useState } from 'react'
2- import { useFavicon , useEventListener , useTitle } from '@brightleaf/react-hooks'
2+ import {
3+ useFavicon ,
4+ useEventListener ,
5+ useTitle ,
6+ useCustomEvent ,
7+ } from '@brightleaf/react-hooks'
38import Home from '../app/home'
9+ import Example from './samples/event.md'
410
511export default ( ) => {
612 useTitle ( 'useEventListener example from @brightleaf/react-hooks' )
@@ -9,7 +15,13 @@ export default () => {
915 const onScroll = e => {
1016 setState ( window . scrollY )
1117 }
18+ const onBrightleafEvent = e => {
19+ console . log ( 'on brightleaf event' , e )
20+ }
1221 useEventListener ( 'scroll' , onScroll )
22+ const fireEvent = useCustomEvent ( 'brightleafEvent' )
23+ useEventListener ( 'brightleafEvent' , onBrightleafEvent )
24+
1325 return (
1426 < div className = "App content" >
1527 < h2 > Scroll the page</ h2 >
@@ -20,9 +32,17 @@ export default () => {
2032 left : 10 ,
2133 background : '#CCCCCC' ,
2234 } }
35+ onClick = { e => {
36+ fireEvent ( {
37+ payload : 'nothing' ,
38+ } )
39+ } }
2340 >
2441 { state } scroll position
2542 </ span >
43+ < br />
44+ < div className = "content" dangerouslySetInnerHTML = { { __html : Example } } />
45+ < br />
2646 < Home > </ Home >
2747 </ div >
2848 )
Original file line number Diff line number Diff line change 11import React from 'react'
2- import {
3- useOnlineStatus ,
4- useTitle ,
5- useMediaQuery ,
6- } from '@brightleaf/react-hooks'
2+ import { useOnlineStatus , useTitle , useMetaTag } from '@brightleaf/react-hooks'
73export default ( ) => {
84 useTitle ( 'useOnlineStatus example from @brightleaf/react-hooks' )
95 const { offline, online } = useOnlineStatus ( )
10-
6+ useMetaTag (
7+ 'description' ,
8+ 'useOnlineStatus hook example from @brightleaf/react-hooks'
9+ )
1110 return (
1211 < div className = "App content" >
1312 < h3 >
Original file line number Diff line number Diff line change 1+ ## Event Hooks Example
2+
3+ ``` jsx
4+ import React , { useState } from ' react'
5+ import { useEventListener , useTitle , useCustomEvent } from ' @brightleaf/react-hooks'
6+
7+ export default () => {
8+
9+ const [state , setState ] = useState (window .scrollY )
10+ const onScroll = e => {
11+ setState (window .scrollY )
12+ }
13+ const onBrightleafEvent = e => {
14+ console .info (' on brightleaf event' , e)
15+ }
16+ useEventListener (' scroll' , onScroll)
17+ const fireEvent = useCustomEvent (' brightleafEvent' )
18+ useEventListener (' brightleafEvent' , onBrightleafEvent)
19+
20+ return (
21+ < div className= " App content" >
22+ < h2> Scroll the page< / h2>
23+ < span
24+ style= {{
25+ position: ' fixed' ,
26+ top: 10 ,
27+ left: 10 ,
28+ background: ' #CCCCCC' ,
29+ }}
30+ onClick= {e => {
31+ fireEvent ({
32+ payload: ' nothing' ,
33+ })
34+ }}
35+ >
36+ {state} scroll position
37+ < / span>
38+ < div> ... page content< / div>
39+ < / div>
40+ )
41+ }
42+ ```
You can’t perform that action at this time.
0 commit comments