Some questions regarding code organization inT3 Stack
Unanswered
Wetterhoun posted this in #help-forum
WetterhounOP
I have couple of questions regarding code organization.
How do you guys handle different states like
In my case, I have a list of
How do you guys handle different states like
isError, isLoading etc. And where does the code of this resides? Does that resides on the page or is there a separate component like SomeEntityListing.tsx to handle these cases etc. Also where does the data fetching logic and code resides?In my case, I have a list of
Projects and I have a ProjectsListing component which fetches and display the data along with their different state. The code looks very spaghetti and I want to move it to something more maintainable.18 Replies
WetterhounOP
My code for
Is this yea or nay?
P.S. Personally I hate this.
ProjectListing.tsx currently looks like thisimport ProjectListItem from "~/components/projects/project-list-item";
import { api } from "~/utils/api";
function ProjectsList_Loading() {
return (
<>
<ProjectListItem project={undefined} />
<ProjectListItem project={undefined} />
</>
);
}
function ProjectList_Empty() {
return (
<div className="flex h-96 items-center justify-center">
Ohh... So empty. Create a project to see them here in the list.
</div>
);
}
function ProjectList_Error() {
return (
<div className="flex h-96 items-center justify-center">
Some error happened while loading the projects. Kindly refresh the page.
</div>
);
}
export default function ProjectsList() {
const projectsQuery = api.projects.getAll.useQuery();
if (projectsQuery.isLoading) {
return ProjectsList_Loading();
}
if (projectsQuery.isError) {
return ProjectList_Error();
}
if (projectsQuery.data?.length === 0) {
return ProjectList_Empty();
}
return projectsQuery.data?.map((project) => (
<ProjectListItem key={project.id} project={project} />
));
}Is this yea or nay?
P.S. Personally I hate this.
yes but camelcase for the name of component
i think it looks fine, why do you hate it?
agred with ray, other than the naming convention i think the code is good
naming then you should use PascalCase for component names
@Ray yes but camelcase for the name of component
oh PascalCase it is!
WetterhounOP
Also where should I store these files?
Currently I am storing them in
src/components/project/, is this the best way to go about it?or do you guys suggest some other convention?
@joulev i think it looks fine, why do you hate it?
WetterhounOP
the logic fetching logic is all over the place. I want something that is more consistent with that, let's call it, The Clean Architectureâ„¢.
I don't know. It just doesn't feel right.
Can't put my figure on it.
even if you tell me so, that The Clean Architectureâ„¢ title doesn't make it any clearer that what kind of thing do you want to get
can you provide some sort of code-ish example?
WetterhounOP
I can't put my figure on it. May be something like the UI/Logic split if you call it.
Or possibly knowing where particular code resides without drilling for it.
May be I should just F- around to find out.
One more thing, what things should reside in
utils vs lib?