Created
February 16, 2023 13:35
-
-
Save koenverburg/0a03d46d10592d30947c8c74810aab4e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
[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