sportsRunning and sportsWalking
up vote
0
down vote
favorite
There are two functions, sportsRunning
and sportsWalking
, that will render different text. For this, I am using an if
condition at the bottom to display corresponding div:
{sportsDescription.sportsDate && sportsDescription.sportsDate.length > 0 && sportsDescription.sportsDate !== '2199-01-01' ?
this.sportsWalking() : this.sportsRunning()}`
Can you tell me how I can refactor the code?
sportsRunning() {
const sportsFire = this.props.profile.firstName;
return (
<div className="sports-table action-shadow">
<h4>{`Want some advice${sportsFire && sportsFire.length > 0 ? `, ${sportsFire}` : ''}?`}</h4>
<p>Stay focused by setting a target date for completion of your sports.</p>
<div className="secondary-links section_content">
<a href="javascript:;" onClick={this.editHandler}>Set Target Date</a>
</div>
</div>
);
}
sportsWalking() {
const sportsFire = this.props.profile.firstName;
return (
<div className="sports-table action-shadow">
<h4>{`Want a helpful tip${sportsFire && sportsFire.length > 0 ? `, ${sportsFire}` : ''}?`}</h4>
<p>Add some momentum to your account by setting up automatic recurring deposits.</p>
<div className="secondary-links section_content">
<a href="javascript:;" onClick={this.editHandler}>Set Up Automatic Deposits</a>
</div>
</div>
);
}
render() {
const {sportsDescription, data} = this.props;
const sportsAmount = parseFloat(sportsDescription.sportsAmount);
const accumulatedAmount = data.summary.total || 0;
return (
<div>
<div className="content-box action-shadow">
{
sportsDescription.error ?
this.renderProgressError() :
this.renderProgress({
accumulatedAmount,
sportsAmount
})
}
<div className="section_content">
<h2>Your Goal Progress</h2>
<p>You have accumulated <strong className={accumulatedAmount >= 0 ? null : 'negative'}>
{moneyFormat(accumulatedAmount)}</strong> towards your sports of <strong>
{moneyFormat(sportsAmount)}</strong>.
</p>
{
sportsDescription.sportsDate && sportsDescription.sportsDate.length > 0 &&
sportsDescription.sportsDate !== '2199-01-01' && this.renderGoalDate(sportsDescription.sportsDate)
}
<div className="secondary-links section_content">
<a href="javascript:;" onClick={this.editHandler}>Edit Goal Details</a>
</div>
</div>
</div>
{sportsDescription.sportsDate && sportsDescription.sportsDate.length > 0 && sportsDescription.sportsDate !== '2199-01-01' ?
this.sportsWalking() : this.sportsRunning()}
</div>
);
beginner html react.js jsx
add a comment |
up vote
0
down vote
favorite
There are two functions, sportsRunning
and sportsWalking
, that will render different text. For this, I am using an if
condition at the bottom to display corresponding div:
{sportsDescription.sportsDate && sportsDescription.sportsDate.length > 0 && sportsDescription.sportsDate !== '2199-01-01' ?
this.sportsWalking() : this.sportsRunning()}`
Can you tell me how I can refactor the code?
sportsRunning() {
const sportsFire = this.props.profile.firstName;
return (
<div className="sports-table action-shadow">
<h4>{`Want some advice${sportsFire && sportsFire.length > 0 ? `, ${sportsFire}` : ''}?`}</h4>
<p>Stay focused by setting a target date for completion of your sports.</p>
<div className="secondary-links section_content">
<a href="javascript:;" onClick={this.editHandler}>Set Target Date</a>
</div>
</div>
);
}
sportsWalking() {
const sportsFire = this.props.profile.firstName;
return (
<div className="sports-table action-shadow">
<h4>{`Want a helpful tip${sportsFire && sportsFire.length > 0 ? `, ${sportsFire}` : ''}?`}</h4>
<p>Add some momentum to your account by setting up automatic recurring deposits.</p>
<div className="secondary-links section_content">
<a href="javascript:;" onClick={this.editHandler}>Set Up Automatic Deposits</a>
</div>
</div>
);
}
render() {
const {sportsDescription, data} = this.props;
const sportsAmount = parseFloat(sportsDescription.sportsAmount);
const accumulatedAmount = data.summary.total || 0;
return (
<div>
<div className="content-box action-shadow">
{
sportsDescription.error ?
this.renderProgressError() :
this.renderProgress({
accumulatedAmount,
sportsAmount
})
}
<div className="section_content">
<h2>Your Goal Progress</h2>
<p>You have accumulated <strong className={accumulatedAmount >= 0 ? null : 'negative'}>
{moneyFormat(accumulatedAmount)}</strong> towards your sports of <strong>
{moneyFormat(sportsAmount)}</strong>.
</p>
{
sportsDescription.sportsDate && sportsDescription.sportsDate.length > 0 &&
sportsDescription.sportsDate !== '2199-01-01' && this.renderGoalDate(sportsDescription.sportsDate)
}
<div className="secondary-links section_content">
<a href="javascript:;" onClick={this.editHandler}>Edit Goal Details</a>
</div>
</div>
</div>
{sportsDescription.sportsDate && sportsDescription.sportsDate.length > 0 && sportsDescription.sportsDate !== '2199-01-01' ?
this.sportsWalking() : this.sportsRunning()}
</div>
);
beginner html react.js jsx
Welcome to CR! Looks like the formatting is a bit off. Take a look at the editing help page for all the information you need to fix the formatting of your post.
– Mathieu Guindon
Aug 10 '16 at 21:30
Can you tell us, what you think could be refactored? Because both functions return different texts, but with the same layout.. If the layout will not change you could create pureRenderComponent ala(props) => (<div></div>)
But if the structure will change at any point, then its fine to keep it separately, then you will have less trouble to customize it
– webdeb
Aug 10 '16 at 22:12
@webdeb layout will not change...but your solution is confusing for me...can you updated in my code
– user3854268
Aug 11 '16 at 13:57
@user3854268 check out my answer
– webdeb
Aug 11 '16 at 14:29
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
There are two functions, sportsRunning
and sportsWalking
, that will render different text. For this, I am using an if
condition at the bottom to display corresponding div:
{sportsDescription.sportsDate && sportsDescription.sportsDate.length > 0 && sportsDescription.sportsDate !== '2199-01-01' ?
this.sportsWalking() : this.sportsRunning()}`
Can you tell me how I can refactor the code?
sportsRunning() {
const sportsFire = this.props.profile.firstName;
return (
<div className="sports-table action-shadow">
<h4>{`Want some advice${sportsFire && sportsFire.length > 0 ? `, ${sportsFire}` : ''}?`}</h4>
<p>Stay focused by setting a target date for completion of your sports.</p>
<div className="secondary-links section_content">
<a href="javascript:;" onClick={this.editHandler}>Set Target Date</a>
</div>
</div>
);
}
sportsWalking() {
const sportsFire = this.props.profile.firstName;
return (
<div className="sports-table action-shadow">
<h4>{`Want a helpful tip${sportsFire && sportsFire.length > 0 ? `, ${sportsFire}` : ''}?`}</h4>
<p>Add some momentum to your account by setting up automatic recurring deposits.</p>
<div className="secondary-links section_content">
<a href="javascript:;" onClick={this.editHandler}>Set Up Automatic Deposits</a>
</div>
</div>
);
}
render() {
const {sportsDescription, data} = this.props;
const sportsAmount = parseFloat(sportsDescription.sportsAmount);
const accumulatedAmount = data.summary.total || 0;
return (
<div>
<div className="content-box action-shadow">
{
sportsDescription.error ?
this.renderProgressError() :
this.renderProgress({
accumulatedAmount,
sportsAmount
})
}
<div className="section_content">
<h2>Your Goal Progress</h2>
<p>You have accumulated <strong className={accumulatedAmount >= 0 ? null : 'negative'}>
{moneyFormat(accumulatedAmount)}</strong> towards your sports of <strong>
{moneyFormat(sportsAmount)}</strong>.
</p>
{
sportsDescription.sportsDate && sportsDescription.sportsDate.length > 0 &&
sportsDescription.sportsDate !== '2199-01-01' && this.renderGoalDate(sportsDescription.sportsDate)
}
<div className="secondary-links section_content">
<a href="javascript:;" onClick={this.editHandler}>Edit Goal Details</a>
</div>
</div>
</div>
{sportsDescription.sportsDate && sportsDescription.sportsDate.length > 0 && sportsDescription.sportsDate !== '2199-01-01' ?
this.sportsWalking() : this.sportsRunning()}
</div>
);
beginner html react.js jsx
There are two functions, sportsRunning
and sportsWalking
, that will render different text. For this, I am using an if
condition at the bottom to display corresponding div:
{sportsDescription.sportsDate && sportsDescription.sportsDate.length > 0 && sportsDescription.sportsDate !== '2199-01-01' ?
this.sportsWalking() : this.sportsRunning()}`
Can you tell me how I can refactor the code?
sportsRunning() {
const sportsFire = this.props.profile.firstName;
return (
<div className="sports-table action-shadow">
<h4>{`Want some advice${sportsFire && sportsFire.length > 0 ? `, ${sportsFire}` : ''}?`}</h4>
<p>Stay focused by setting a target date for completion of your sports.</p>
<div className="secondary-links section_content">
<a href="javascript:;" onClick={this.editHandler}>Set Target Date</a>
</div>
</div>
);
}
sportsWalking() {
const sportsFire = this.props.profile.firstName;
return (
<div className="sports-table action-shadow">
<h4>{`Want a helpful tip${sportsFire && sportsFire.length > 0 ? `, ${sportsFire}` : ''}?`}</h4>
<p>Add some momentum to your account by setting up automatic recurring deposits.</p>
<div className="secondary-links section_content">
<a href="javascript:;" onClick={this.editHandler}>Set Up Automatic Deposits</a>
</div>
</div>
);
}
render() {
const {sportsDescription, data} = this.props;
const sportsAmount = parseFloat(sportsDescription.sportsAmount);
const accumulatedAmount = data.summary.total || 0;
return (
<div>
<div className="content-box action-shadow">
{
sportsDescription.error ?
this.renderProgressError() :
this.renderProgress({
accumulatedAmount,
sportsAmount
})
}
<div className="section_content">
<h2>Your Goal Progress</h2>
<p>You have accumulated <strong className={accumulatedAmount >= 0 ? null : 'negative'}>
{moneyFormat(accumulatedAmount)}</strong> towards your sports of <strong>
{moneyFormat(sportsAmount)}</strong>.
</p>
{
sportsDescription.sportsDate && sportsDescription.sportsDate.length > 0 &&
sportsDescription.sportsDate !== '2199-01-01' && this.renderGoalDate(sportsDescription.sportsDate)
}
<div className="secondary-links section_content">
<a href="javascript:;" onClick={this.editHandler}>Edit Goal Details</a>
</div>
</div>
</div>
{sportsDescription.sportsDate && sportsDescription.sportsDate.length > 0 && sportsDescription.sportsDate !== '2199-01-01' ?
this.sportsWalking() : this.sportsRunning()}
</div>
);
beginner html react.js jsx
beginner html react.js jsx
edited Nov 10 '16 at 2:58
200_success
127k15148412
127k15148412
asked Aug 10 '16 at 21:01
user3854268
13
13
Welcome to CR! Looks like the formatting is a bit off. Take a look at the editing help page for all the information you need to fix the formatting of your post.
– Mathieu Guindon
Aug 10 '16 at 21:30
Can you tell us, what you think could be refactored? Because both functions return different texts, but with the same layout.. If the layout will not change you could create pureRenderComponent ala(props) => (<div></div>)
But if the structure will change at any point, then its fine to keep it separately, then you will have less trouble to customize it
– webdeb
Aug 10 '16 at 22:12
@webdeb layout will not change...but your solution is confusing for me...can you updated in my code
– user3854268
Aug 11 '16 at 13:57
@user3854268 check out my answer
– webdeb
Aug 11 '16 at 14:29
add a comment |
Welcome to CR! Looks like the formatting is a bit off. Take a look at the editing help page for all the information you need to fix the formatting of your post.
– Mathieu Guindon
Aug 10 '16 at 21:30
Can you tell us, what you think could be refactored? Because both functions return different texts, but with the same layout.. If the layout will not change you could create pureRenderComponent ala(props) => (<div></div>)
But if the structure will change at any point, then its fine to keep it separately, then you will have less trouble to customize it
– webdeb
Aug 10 '16 at 22:12
@webdeb layout will not change...but your solution is confusing for me...can you updated in my code
– user3854268
Aug 11 '16 at 13:57
@user3854268 check out my answer
– webdeb
Aug 11 '16 at 14:29
Welcome to CR! Looks like the formatting is a bit off. Take a look at the editing help page for all the information you need to fix the formatting of your post.
– Mathieu Guindon
Aug 10 '16 at 21:30
Welcome to CR! Looks like the formatting is a bit off. Take a look at the editing help page for all the information you need to fix the formatting of your post.
– Mathieu Guindon
Aug 10 '16 at 21:30
Can you tell us, what you think could be refactored? Because both functions return different texts, but with the same layout.. If the layout will not change you could create pureRenderComponent ala
(props) => (<div></div>)
But if the structure will change at any point, then its fine to keep it separately, then you will have less trouble to customize it– webdeb
Aug 10 '16 at 22:12
Can you tell us, what you think could be refactored? Because both functions return different texts, but with the same layout.. If the layout will not change you could create pureRenderComponent ala
(props) => (<div></div>)
But if the structure will change at any point, then its fine to keep it separately, then you will have less trouble to customize it– webdeb
Aug 10 '16 at 22:12
@webdeb layout will not change...but your solution is confusing for me...can you updated in my code
– user3854268
Aug 11 '16 at 13:57
@webdeb layout will not change...but your solution is confusing for me...can you updated in my code
– user3854268
Aug 11 '16 at 13:57
@user3854268 check out my answer
– webdeb
Aug 11 '16 at 14:29
@user3854268 check out my answer
– webdeb
Aug 11 '16 at 14:29
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
This is what I mean with pureRenderComponent:
const SportsMoving = ({editHandler, sportsDescription, ...props }) => {
const isRunning = sportsDescription.sportsDate && sportsDescription.sportsDate.length > 0 && sportsDescription.sportsDate !== '2199-01-01';
const sportFire = props.profile.firstName || "";
return (
<div className="sports-table action-shadow">
<h4>
{
isRunning
? `Want some advice ${sportFire}?`
: `Want a helpful tip ${sportsFire}?`
}
</h4>
<p>
{
isRunning
? "Stay focused by setting a target date for completion of your sports."
: "Add some momentum to your account by setting up automatic recurring deposits."
}
</p>
<div className="secondary-links section_content">
<a href="javascript:;" onClick={editHandler}>
{
isRunning
? "Set Target Date"
: "Set Up Automatic Deposits"
}
</a>
</div>
</div>
)
}
now in your parentComponent you can use it like so:
...
</div>
<SportsMoving editHandler={this.editHandler} ...props />
</div>
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
This is what I mean with pureRenderComponent:
const SportsMoving = ({editHandler, sportsDescription, ...props }) => {
const isRunning = sportsDescription.sportsDate && sportsDescription.sportsDate.length > 0 && sportsDescription.sportsDate !== '2199-01-01';
const sportFire = props.profile.firstName || "";
return (
<div className="sports-table action-shadow">
<h4>
{
isRunning
? `Want some advice ${sportFire}?`
: `Want a helpful tip ${sportsFire}?`
}
</h4>
<p>
{
isRunning
? "Stay focused by setting a target date for completion of your sports."
: "Add some momentum to your account by setting up automatic recurring deposits."
}
</p>
<div className="secondary-links section_content">
<a href="javascript:;" onClick={editHandler}>
{
isRunning
? "Set Target Date"
: "Set Up Automatic Deposits"
}
</a>
</div>
</div>
)
}
now in your parentComponent you can use it like so:
...
</div>
<SportsMoving editHandler={this.editHandler} ...props />
</div>
add a comment |
up vote
0
down vote
This is what I mean with pureRenderComponent:
const SportsMoving = ({editHandler, sportsDescription, ...props }) => {
const isRunning = sportsDescription.sportsDate && sportsDescription.sportsDate.length > 0 && sportsDescription.sportsDate !== '2199-01-01';
const sportFire = props.profile.firstName || "";
return (
<div className="sports-table action-shadow">
<h4>
{
isRunning
? `Want some advice ${sportFire}?`
: `Want a helpful tip ${sportsFire}?`
}
</h4>
<p>
{
isRunning
? "Stay focused by setting a target date for completion of your sports."
: "Add some momentum to your account by setting up automatic recurring deposits."
}
</p>
<div className="secondary-links section_content">
<a href="javascript:;" onClick={editHandler}>
{
isRunning
? "Set Target Date"
: "Set Up Automatic Deposits"
}
</a>
</div>
</div>
)
}
now in your parentComponent you can use it like so:
...
</div>
<SportsMoving editHandler={this.editHandler} ...props />
</div>
add a comment |
up vote
0
down vote
up vote
0
down vote
This is what I mean with pureRenderComponent:
const SportsMoving = ({editHandler, sportsDescription, ...props }) => {
const isRunning = sportsDescription.sportsDate && sportsDescription.sportsDate.length > 0 && sportsDescription.sportsDate !== '2199-01-01';
const sportFire = props.profile.firstName || "";
return (
<div className="sports-table action-shadow">
<h4>
{
isRunning
? `Want some advice ${sportFire}?`
: `Want a helpful tip ${sportsFire}?`
}
</h4>
<p>
{
isRunning
? "Stay focused by setting a target date for completion of your sports."
: "Add some momentum to your account by setting up automatic recurring deposits."
}
</p>
<div className="secondary-links section_content">
<a href="javascript:;" onClick={editHandler}>
{
isRunning
? "Set Target Date"
: "Set Up Automatic Deposits"
}
</a>
</div>
</div>
)
}
now in your parentComponent you can use it like so:
...
</div>
<SportsMoving editHandler={this.editHandler} ...props />
</div>
This is what I mean with pureRenderComponent:
const SportsMoving = ({editHandler, sportsDescription, ...props }) => {
const isRunning = sportsDescription.sportsDate && sportsDescription.sportsDate.length > 0 && sportsDescription.sportsDate !== '2199-01-01';
const sportFire = props.profile.firstName || "";
return (
<div className="sports-table action-shadow">
<h4>
{
isRunning
? `Want some advice ${sportFire}?`
: `Want a helpful tip ${sportsFire}?`
}
</h4>
<p>
{
isRunning
? "Stay focused by setting a target date for completion of your sports."
: "Add some momentum to your account by setting up automatic recurring deposits."
}
</p>
<div className="secondary-links section_content">
<a href="javascript:;" onClick={editHandler}>
{
isRunning
? "Set Target Date"
: "Set Up Automatic Deposits"
}
</a>
</div>
</div>
)
}
now in your parentComponent you can use it like so:
...
</div>
<SportsMoving editHandler={this.editHandler} ...props />
</div>
edited Apr 9 '17 at 15:03
answered Aug 11 '16 at 14:28
webdeb
48324
48324
add a comment |
add a comment |
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f138385%2fsportsrunning-and-sportswalking%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Welcome to CR! Looks like the formatting is a bit off. Take a look at the editing help page for all the information you need to fix the formatting of your post.
– Mathieu Guindon
Aug 10 '16 at 21:30
Can you tell us, what you think could be refactored? Because both functions return different texts, but with the same layout.. If the layout will not change you could create pureRenderComponent ala
(props) => (<div></div>)
But if the structure will change at any point, then its fine to keep it separately, then you will have less trouble to customize it– webdeb
Aug 10 '16 at 22:12
@webdeb layout will not change...but your solution is confusing for me...can you updated in my code
– user3854268
Aug 11 '16 at 13:57
@user3854268 check out my answer
– webdeb
Aug 11 '16 at 14:29