Skip to content

Commit

Permalink
perf: 去掉 jsx 里面的随机 key
Browse files Browse the repository at this point in the history
  • Loading branch information
Mereithhh committed Sep 1, 2022
1 parent df5d308 commit 29fdb23
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 22 deletions.
2 changes: 0 additions & 2 deletions packages/admin/src/pages/DataManage/tabs/Donate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export default function () {
}}
recordCreatorProps={{
position: 'bottom',
record: () => ({ key: Math.floor(Math.random() * 1000000) }),
}}
loading={false}
columns={columns}
Expand All @@ -104,7 +103,6 @@ export default function () {
type: 'multiple',
editableKeys,
onSave: async (rowKey, data, row) => {

await updateDonate(data);
actionRef?.current?.reload();
},
Expand Down
1 change: 0 additions & 1 deletion packages/admin/src/pages/DataManage/tabs/Link.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ export default function () {
}}
recordCreatorProps={{
position: 'bottom',
record: () => ({ key: Math.floor(Math.random() * 1000000) }),
}}
loading={false}
columns={columns}
Expand Down
1 change: 0 additions & 1 deletion packages/admin/src/pages/DataManage/tabs/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export default function () {
}}
recordCreatorProps={{
position: 'bottom',
record: () => ({ key: Math.floor(Math.random() * 1000000) }),
}}
loading={false}
columns={columns}
Expand Down
1 change: 0 additions & 1 deletion packages/admin/src/pages/DataManage/tabs/Social.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export default function () {
}}
recordCreatorProps={{
position: 'bottom',
record: () => ({ key: Math.floor(Math.random() * 1000000) }),
}}
loading={false}
columns={columns}
Expand Down
4 changes: 0 additions & 4 deletions packages/website/components/PageNav/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,3 @@ export const calItemList = (props: PageNavProps) => {
}
return res;
};

export const randomKey = (item: PageItem) => {
return `${Math.floor(Math.random() * 100000)}-${item.href}`;
};
16 changes: 11 additions & 5 deletions packages/website/components/PageNav/render.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Link from "next/link";
import { CSSProperties, HTMLAttributes } from "react";
import { PageItem, randomKey } from "./core";
import { CSSProperties } from "react";
import { PageItem } from "./core";
const commonCls =
"inline-flex justify-center items-center transition-all text-gray-600";
const btnCls =
Expand All @@ -13,7 +13,10 @@ const commonStyle: CSSProperties = {
};
const renderLink = (item: PageItem, isCur: boolean) => {
return (
<Link href={item.href} key={randomKey(item)}>
<Link
href={item.href}
key={`LinkItem-${item.page}-${item.type}-${item.href}`}
>
<a
style={commonStyle}
className={`${commonCls} ${btnCls} ${
Expand All @@ -31,7 +34,7 @@ const renderBtn = (item: PageItem, disable: boolean, isNext: boolean) => {
return (
<Link
href={item.href}
key={randomKey(item)}
key={`pagenav-btn-${item.page}-${item.href}-${isNext}`}
// className="justify-center items-center "
>
<a
Expand All @@ -45,7 +48,10 @@ const renderBtn = (item: PageItem, disable: boolean, isNext: boolean) => {
};
const renderMore = (item: PageItem, isNext: boolean) => {
return (
<Link href={item.href} key={randomKey(item)}>
<Link
href={item.href}
key={`pagenav-more-${item.page}-${item.href}-${isNext}`}
>
<a style={commonStyle} className={`dark:pg-text-dark ${commonCls}`}>
•••
</a>
Expand Down
2 changes: 1 addition & 1 deletion packages/website/components/PostCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export default function (props: {
<div className="mt-4">
<div className="text-sm text-gray-500 flex justify-center space-x-2 select-none dark:text-dark">
{props.tags.map((tag) => (
<div key={Math.floor(Math.random() * 100000)}>
<div key={`article-tag-${tag}`}>
<Link href={`/tag/${tag}`}>
<a className=" border-b border-white hover:border-gray-500 dark:border-dark dark:hover:border-gray-300 dark:hover:text-gray-300">{`#${tag}`}</a>
</Link>
Expand Down
4 changes: 2 additions & 2 deletions packages/website/components/SocialCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ export default function (props: { socials: SocialItem[] }) {

return (
<div className="flex flex-col justify-center items-center">
{data.map((eachRow: SocialItem[]) => {
{data.map((eachRow: SocialItem[], index) => {
return (
<div
className="w-full flex flex-row justify-between items-center"
key={Math.floor(Math.random() * 1000000)}
key={`socalRow-${index}`}
>
{renderEach(eachRow[0])}
{renderEach(eachRow[1])}
Expand Down
5 changes: 1 addition & 4 deletions packages/website/pages/tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ const TagPage = (props: TagPageProps) => {
</div>
<div className="flex flex-wrap mt-2">
{props.tags.map((tag) => (
<Link
href={`/tag/${tag}`}
key={Math.floor(Math.random() * 1000000)}
>
<Link href={`/tag/${tag}`} key={`tag-${tag}`}>
<a className="my-2 text-gray-500 block hover:text-gray-900 dark:hover:text-dark-hover transform hover:scale-110 transition-all mr-5 dark:text-dark-400 ">{`#${tag}`}</a>
</Link>
))}
Expand Down
2 changes: 1 addition & 1 deletion packages/website/pages/timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const TimeLine = (props: TimeLinePageProps) => {
return (
<TimeLineItem
defaultOpen={true}
key={Math.floor(Math.random() * 1000000)}
key={`timeline-dateitem-${eachDate}`}
date={eachDate}
articles={props.sortedArticles[eachDate]}
></TimeLineItem>
Expand Down

0 comments on commit 29fdb23

Please sign in to comment.