Code Formatting #46
Unanswered
GauravGusain98
asked this question in
Software Principles
Replies: 3 comments 1 reply
|
Yes there are some things that can be formatted to improve the readability of the component like in this import statement import React from 'react'
import styled from 'styled-components'
import { Empty, List } from 'antd'
import BookCard from './BookCard'
const StyledList = styled(List)`
/* ... */
`
const StyledListItem = styled(List.Item)`
/* ... */
`
const SectionHeader = styled.div`
/* ... */
`
const Wrapper = styled.div`
/* ... */
`
const BookGrid = ({
books,
title,
booksPerPage,
onPageChange,
onClickDelete,
totalCount,
currentPage,
loading,
}) => {
const paginationConfig = {
pageSize: booksPerPage,
current: currentPage,
showSizeChanger: false,
onChange: onPageChange,
}
return (
<Wrapper>
<SectionHeader>{title && <h2>{title}</h2>}</SectionHeader>
<StyledList
dataSource={books}
grid={{ gutter: 64,
xs: 1,
sm: 2,
md: 4,
lg: 5,
xl: 5,
xxl: 5
}}
itemLayout="horizontal"
loading={loading}
locale={{
emptyText: (
<Empty
description={<span>You don’t have any books yet</span>}
image={Empty.PRESENTED_IMAGE_SIMPLE}
/>
),
}}
pagination={paginationConfig}
renderItem={(book) => (
<StyledListItem>
<BookCard {...book} onClickDelete={onClickDelete} showActions />
</StyledListItem>
)}
showPagination={totalCount > 10}
totalCount={totalCount}
/>
</Wrapper>
)
} |
0 replies
|
My answer is quite similar to Abhishek's, just adding a bit more formatting. import React from 'react'
import styled from 'styled-components'
import { Empty, List } from 'antd'
import BookCard from './BookCard'
const StyledList = styled(List)`
/* ... */
`
const StyledListItem = styled(List.Item)`
/* ... */
`
const SectionHeader = styled.div`
/* ... */
`
const Wrapper = styled.div`
/* ... */
`
const BookGrid = ({
books,
title,
booksPerPage,
onPageChange,
onClickDelete,
totalCount,
currentPage,
loading
}) => {
const paginationConfig = {
pageSize: booksPerPage,
current: currentPage,
showSizeChanger: false,
onChange: onPageChange
}
return (
<Wrapper>
<SectionHeader>
{title && <h2>{title}</h2>}
</SectionHeader>
<StyledList
dataSource={books}
grid={{
gutter: 64,
xs: 1,
sm: 2,
md: 4,
lg: 5,
xl: 5,
xxl: 5,
}}
itemLayout="horizontal"
loading={loading}
locale={{
emptyText: (
<Empty description={<span>You don’t have any books yet</span>}
image={Empty.PRESENTED_IMAGE_SIMPLE}
/>
),
}}
pagination={paginationConfig}
renderItem={book => (
<StyledListItem>
<BookCard {...book} onClickDelete={onClickDelete} showActions />
</StyledListItem>
)}
showPagination={totalCount > 10}
totalCount={totalCount}
/>
</Wrapper>
)
} |
1 reply
|
To pass the props as separate constants instead of directly within the component definition, can do so by creating a separate object that holds all the props and then passing that object as an argument to the component. separating the props into a separate constant can improve code readability in certain scenarios. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Do you think the code for the React component
BookGridcan be formatted better to enhance readability?All reactions