Skip to content

Commit

Permalink
Add links for help (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospassos authored Aug 11, 2024
1 parent 7225517 commit e6ab3be
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/hooks/useContent.ssr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ describe('useContent (SSR)', () => {

it('should require an initial value for server-side rending', () => {
expect(() => useContent('slot-id'))
.toThrow(new Error('The initial value is required for server-side rendering (SSR).'));
.toThrow('The initial content is required for server-side rendering (SSR).');
});
});
5 changes: 4 additions & 1 deletion src/hooks/useContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ function useSsrContent<I, F>(
{initial}: UseContentOptions<I, F> = {},
): SlotContent | I | F {
if (initial === undefined) {
throw new Error('The initial value is required for server-side rendering (SSR).');
throw new Error(
'The initial content is required for server-side rendering (SSR). '
+ 'For help, see https://croct.help/sdk/react/missing-initial-slot-content',
);
}

return initial;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useCroct.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('useCroct', () => {
jest.spyOn(console, 'error').mockImplementation();

expect(() => renderHook(() => useCroct()))
.toThrow(new Error('useCroct() can only be used in the context of a <CroctProvider> component.'));
.toThrow('useCroct() can only be used in the context of a <CroctProvider> component.');

// eslint-disable-next-line no-console -- Testing console output.
expect(console.error).toHaveBeenCalled();
Expand Down
5 changes: 4 additions & 1 deletion src/hooks/useCroct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ export function useCroct(): Plug {
const context = useContext(CroctContext);

if (context === null) {
throw new Error('useCroct() can only be used in the context of a <CroctProvider> component.');
throw new Error(
'useCroct() can only be used in the context of a <CroctProvider> component. '
+ 'For help, see https://croct.help/sdk/react/missing-provider',
);
}

return context.plug;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useEvaluation.ssr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ describe('useEvaluation (SSR)', () => {

it('should require an initial value for server-side rending', () => {
expect(() => useEvaluation('location'))
.toThrow(new Error('The initial value is required for server-side rendering (SSR).'));
.toThrow('The initial value is required for server-side rendering (SSR).');
});
});
5 changes: 4 additions & 1 deletion src/hooks/useEvaluation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ function useSsrEvaluation<T = JsonValue, I = T, F = T>(
{initial}: UseEvaluationOptions<I, F> = {},
): T | I | F {
if (initial === undefined) {
throw new Error('The initial value is required for server-side rendering (SSR).');
throw new Error(
'The initial value is required for server-side rendering (SSR). '
+ 'For help, see https://croct.help/sdk/react/missing-initial-evaluation-value',
);
}

return initial;
Expand Down
3 changes: 2 additions & 1 deletion src/ssr-polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export const croct: Plug = !isSsr()
throw new Error(
`Property croct.${String(property)} is not supported on server-side (SSR). `
+ 'Consider refactoring the logic as a side-effect (useEffect) or a client-side callback '
+ '(onClick, onChange, etc).',
+ '(onClick, onChange, etc). '
+ 'For help, see https://croct.help/sdk/react/client-side-methods',
);
}
},
Expand Down

0 comments on commit e6ab3be

Please sign in to comment.