Skip to content

Instantly share code, notes, and snippets.

@koenverburg
Created February 16, 2023 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koenverburg/0a03d46d10592d30947c8c74810aab4e to your computer and use it in GitHub Desktop.
Save koenverburg/0a03d46d10592d30947c8c74810aab4e to your computer and use it in GitHub Desktop.
[react-class-to-functional-component]
# Geven this as input this should rewrite it in a functional component
#export class Example extends React.Component {
# componentDidMount() {
# // hii from componentDidMount
# }
# componentWillUnmount() {
# // hii from componentWillUnmount
# }
# render () {
# return (
# <div>
# This text is all that renders. And the modal is not rendered, regardless
# of whether it is contained within this div.
# </div>
# )
# }
#}
match='''
class :[name] extends React.Component {
componentDidMount() {
:[mount]
}
componentWillUnmount() {
:[unmount]
}
render () {
return (:[jsx])
}
}
'''
rewrite='''
export const :[name] = () => {
React.useEffect(() => {
:[mount]
return () => {
:[unmount]
}
}, [])
return (:[jsx])
}
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment