Last active
May 7, 2021 12:22
-
-
Save ilkou/0acc33eee43e9a323c6c8ffa056d0582 to your computer and use it in GitHub Desktop.
Intellij/WebStorm live template to create a React Context Component with FlowTypes
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
// @flow | |
import * as React from 'react'; | |
import { createContext, useContext, useState } from 'react'; | |
export const $TM_FILENAME_BASE$ = createContext(); | |
export function use$TM_FILENAME_BASE$() { | |
return useContext($TM_FILENAME_BASE$); | |
} | |
export const $NAME$Consumer = $TM_FILENAME_BASE$.Consumer; | |
// eslint-disable-next-line react/prop-types | |
export const $NAME$Provider = ({ children }) => { | |
const [state, setState] = useState(null); | |
const value = { | |
state, | |
setState, | |
}; | |
return ( | |
<$TM_FILENAME_BASE$.Provider value={value}> | |
{children} | |
</$TM_FILENAME_BASE$.Provider> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
EXAMPLE:
filename:
output:
usage
simply type
rci
in your new created fileinstallation
Preferences -> Editor -> Live templates -> add live template
Copy paste code from gist
Define following variables (Click on edit Variable)
Or import following file: React.xml example