-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: changed Output into a functional component w/ hooks #686
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly good, there are just a few issues, mostly with the memoization
const [firstLoad, setFirstLoad] = useState(true); | ||
|
||
useEffect(() => { | ||
setFirstLoad(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the shouldComponentUpdate
function was refactored correctly. You should pass in a second argument to react memo. Additionally, the useEffect dependency array should correspond to line 43-45 in the old file.
} | ||
|
||
if (this.props.mostRecentProgram !== nextProps.mostRecentProgram) { | ||
this.firstLoad = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This functionality is not preserved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setFirstLoad
should be called when mostRecentProgram
changes
src/components/Output/Output.js
Outdated
); | ||
|
||
const toggleConsole = () => { | ||
setShowConsole((prevShowConsole) => !prevShowConsole); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can just be setShowConsole(!showConsole)
); | ||
|
||
const runCode = () => { | ||
setRun((prevRun) => prevRun + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should just be the run state, instead of this function
@lumisphere902 One note: I didn't change my |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of elaborations; also there are a few lint changes needed
} | ||
|
||
if (this.props.mostRecentProgram !== nextProps.mostRecentProgram) { | ||
this.firstLoad = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setFirstLoad
should be called when mostRecentProgram
changes
showConsole: true, | ||
}; | ||
this.firstLoad = true; | ||
const compareProps = (prevProps, nextProps) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true
should be returned when the component should not update; you reversed it
@lpizzinidev Would you like to resolve conflicts and we can merge in? Thanks! |
Closes #670