-
Notifications
You must be signed in to change notification settings - Fork 56
CodeGuideline
We use prettier and a linter. Please make sure your code editor is correctly configured.
- Format your commits with Conventional Commit (emojis are welcome though 😜)
- Any component prop referring to an action must be prefixed by
on
(ex:onSubmit
)
Refer to Design Guidelines
- Use mainly absolute imports :
~/page/Home
, it will be easier to update it the file is moved
- Except for
pages
, prefer named export over default exports. This will allow us to avoid mistypings in component/functions names - For lodash, import with the following way :
import _get from 'lodash/get'
- for a better tree-shaking
If you need to document a lot, it's because your code isn't clear enough. Try to change variable names, cut components in smaller ones. Someone should be easily able to take over your code if needed.
When you do something, try to think about refactoring that code. Use variable for any hard coded value (like route names etc...). Use enums whenever you can.
To avoid dead code, all the style should be in the same file as the TS code using it. If you use the same style several time (general rule is >= 3 times but that's up to you) consider making a reusable style file.
Always use the hooks generated with the codegen to query or mutate datas from the api.
- Define your qgl schema
- Run
yarn codegen
- Use the hook and/or the fragment generated
// Sub component OrganizationDetails
import { CurrentOrganizationFragment } from "~/generated/graphql";
gql`
fragment CurrentOrganization on Organization {
id
name
}
`;
export const OrganizationDetails = (
organisation: CurrentOrganizationFragment
) => {
return <div>{organisation.name}</div>;
};
// Parent component UserInfo
import {
useUserIdentifierQuery,
CurrentOrganizationFragmentDoc,
useUpdateUserMutation,
} from "~/generated/graphql";
import { OrganizationDetails } from "./OrganizationDetails";
gql`
query UserIdentifier {
currentUser {
id
email
organisation {
...CurrentOrganizationFragmentDoc
}
}
}
muation updateUser($input: UserInput!) {
updateUser(input: $input) {
id
}
}
${CurrentOrganizationFragmentDoc}
`;
const UserIdentifier = () => {
const { data, loading, error } = useUserIdentifierQuery();
const [updateUser] = useUpdateUserMutation();
return (
<div>
<div>User email : {data?.currentUser?.email}</div>
<OrganizationDetails organisation={data?.currentUser?.organisation} />
</div>
);
};
Note : One query will generate 2 hooks : useYourQueryNameQuery & useYourQueryNameLazyQuery