Skip to content

World Clock - Patrick#63

Open
patrickkok wants to merge 4 commits intorocketacademy:mainfrom
patrickkok:main
Open

World Clock - Patrick#63
patrickkok wants to merge 4 commits intorocketacademy:mainfrom
patrickkok:main

Conversation

@patrickkok
Copy link

No description provided.

Comment on lines +11 to +30
this.state = {
display: <></>,
};
this.timezonesInput = React.createRef();
this.inputForm = (
<Form className="w-50" onSubmit={() => this.submit()}>
<Form.Group className="mb-3">
<Form.Label>Set-up your clocks</Form.Label>
<Form.Control
type="text"
placeholder="Asia/Singapore America/Detroit"
ref={this.timezonesInput}
/>
</Form.Group>
<Button variant="light" onClick={() => this.submit()}>
Show me the time!
</Button>
</Form>
);
this.state.display = this.inputForm;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole definition could be simplified I think. Why do you need all the rendered elements in the state? I think it would be wiser to just render those in the component.

this.state = {
display: <></>,
};
this.timezonesInput = React.createRef();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the ref necessary? What are you trying to achieve by using this?

import "bootstrap/dist/css/bootstrap.min.css";
import { Form, Button } from "react-bootstrap";

class WorldClock extends React.Component {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this component necessary? I feel like it just adds another layer but doesn't really do anything

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. It is the component of the last step, though you have implemented it differently than what the instructions told you. In this case I feel this component is somewhat redundant, therefore the comment above

};
this.timezonesInput = React.createRef();
this.inputForm = (
<Form className="w-50" onSubmit={() => this.submit()}>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need a form? I think a simple input + state update would be sufficient here. Or do you have a reason to use a form?

return (
<p className="m-0">
{this.state.date.toLocaleString("en-GB", {
timeZone: this.props.timeZone,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this value does not need to come from a user input tbh. But rather should be a static display based on a time zone. If you want the user to define these, of course you can do it however - then you need to worry about where to store that input.

Overall I feel there is a bit too much abstraction in this file. You could simplify this by taking away some layers, by defining what you want to achieve more clearly and rethinking how you want to utilize state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments