Skip to content
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

Frontend/#043 button and link components #56

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions client/src/components/Button/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React from 'react';

function Button({ textToDisplay }) {
return <button className="button">{textToDisplay}</button>;
function Button({ textToDisplay, classes, callback }) {
return (
<button className={classes} onClick={callback}>
{textToDisplay}
</button>
);
}
Comment on lines +3 to 9
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't you think it's way more complicated to use buttons like this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you suggest any specific solution to this problem?

Copy link
Collaborator

@aleksanderwalczuk aleksanderwalczuk Mar 1, 2021

Choose a reason for hiding this comment

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

@synowa just use buttons as standard jsx element. There's no need to extract it to a separate component right now.
Let's say:

<codeBefore/>
<button anyPropsINeedRightNow>anyText</button>
<codeAfter/>

Pros:

  1. No imports (less messy components directory in the future)
  2. Every additional prop that's not defined in Button component would have to be declared

If your not able to define how many props you'll need then you should use the spread operator

const Example = (props) => (
    <someElement ...props>{props.children}</someElement>
);

props.children stands for any child you put inside this component, eg. text or another component

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I actually had in mind a very specific button, with specific style and function - a go back button, using props.history.goBack(). But I didn't have time to implement it yet. So far yes, it is reduntant.


export default Button;
12 changes: 12 additions & 0 deletions client/src/components/LinkAsButton/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import { Link } from 'react-router-dom';

function LinkAsButton({textToDisplay, classes, pathToRedicrect}) {
return (
<Link className={classes} to={pathToRedicrect}>
{textToDisplay}
</Link>
)
}

export default LinkAsButton
Empty file.
8 changes: 8 additions & 0 deletions client/src/components/LinkAsButton/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { render, screen } from '@testing-library/react';
import LinkAsButton from '.';

test('renders learn react link', () => {
render(<LinkAsButton />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});