Skip to content

Commit

Permalink
docs: Simplify ProfileEdit in homepage demo
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Jul 31, 2024
1 parent 277c38c commit e5a5ccc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function PostList() {
const { posts } = useSuspense(PostResource.getList, { userId });
return (
<div>
<ProfileEdit userId={userId} />
<ProfileEdit id={userId} />
<br />
<br />
{posts.map(post => (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { UserResource } from './resources';

export default function ProfileEdit({ userId }: { userId: number }) {
const { user } = useSuspense(UserResource.get, { id: userId });
export default function ProfileEdit({ id }: { id: number }) {
const { user } = useSuspense(UserResource.get, { id });
const controller = useController();
const handleChange = ({ currentTarget: { value } }) =>
controller.fetch(UserResource.update, {
id: userId,
name: value,
});
const handleChange = ({ currentTarget: { value: name } }) =>
controller.fetch(UserResource.update, { id, name });

return (
<label>
Name:{' '}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function PostList() {
const posts = useSuspense(PostResource.getList, { userId });
return (
<div>
<ProfileEdit userId={userId} />
<ProfileEdit id={userId} />
<br />
<br />
{posts.map(post => (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { UserResource } from './resources';

export default function ProfileEdit({ userId }: { userId: number }) {
const user = useSuspense(UserResource.get, { id: userId });
export default function ProfileEdit({ id }: { id: number }) {
const user = useSuspense(UserResource.get, { id });
const controller = useController();
const handleChange = ({ currentTarget: { value } }) =>
controller.fetch(
UserResource.partialUpdate,
{ id: userId },
{ name: value },
);
const handleChange = ({ currentTarget: { value: name } }) =>
controller.fetch(UserResource.partialUpdate, { id }, { name });

return (
<label>
Name:{' '}
Expand Down

0 comments on commit e5a5ccc

Please sign in to comment.