-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mobile - Move Clipboard context/provider into a singleton
- Loading branch information
Gerardo Pacheco
committed
Dec 29, 2020
1 parent
0bc39c9
commit b71e852
Showing
5 changed files
with
76 additions
and
87 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,18 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createContext, useCallback, useState } from '@wordpress/element'; | ||
const createClipboard = () => { | ||
let currentClipboard; | ||
|
||
export const ClipboardContext = createContext( {} ); | ||
const { Provider, Consumer } = ClipboardContext; | ||
export { Consumer as ClipboardConsumer }; | ||
const setClipboard = ( clipboard ) => { | ||
currentClipboard = clipboard; | ||
}; | ||
|
||
export default function ClipboardProvider( { children } ) { | ||
const [ clipboard, setClipboard ] = useState(); | ||
const updateClipboard = useCallback( ( clipboardUpdate ) => { | ||
setClipboard( clipboardUpdate ); | ||
}, [] ); | ||
const getClipboard = () => currentClipboard; | ||
|
||
return ( | ||
<Provider value={ { clipboard, updateClipboard } }> | ||
{ children } | ||
</Provider> | ||
); | ||
} | ||
return { | ||
setClipboard, | ||
getClipboard, | ||
}; | ||
}; | ||
|
||
const clipboard = createClipboard(); | ||
|
||
export const { setClipboard, getClipboard } = clipboard; |
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