Skip to content

Commit

Permalink
Added new ruleset for prettier and updated global state object to ref…
Browse files Browse the repository at this point in the history
…lect the actual project
  • Loading branch information
tomdng committed Mar 19, 2020
1 parent f4a96e7 commit 1ae0b8a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
"extends": [
"airbnb",
"prettier",
"prettier/react",
"plugin:prettier/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended"
Expand Down
8 changes: 5 additions & 3 deletions src/components/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const Column: AnyStyledComponent = styled.div`
`;

const TutorialApp: React.FC = (): JSX.Element => {
const [step, setStep] = useGlobal("step");
const [tutorialStep, setTutorialStep] = useGlobal("tutorialStep");

return (
<StyledTutorialPage>
Expand All @@ -58,9 +58,11 @@ const TutorialApp: React.FC = (): JSX.Element => {
<h3 className="text-center">Output will go here</h3>
<button
type="button"
onClick={(): Promise<{ step: number }> => setStep(step + 1)}
onClick={(): Promise<{ tutorialStep: number }> =>
setTutorialStep(tutorialStep + 1)
}
>
{step}: Click to increase
{tutorialStep}: Click to increase
</button>
</Column>
</MainWrapper>
Expand Down
10 changes: 7 additions & 3 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import "reactn";

// This sets the shape of our global state since we want our global
// state to be typed.
/*
This sets the shape of our global state since we want our global
state to be typed. Should be the same shape as the global object
initialized in src/pages/index.tsx
*/
declare module "reactn/default" {
export interface State {
step: number;
tutorialName: string;
tutorialStep: number;
}
}
10 changes: 8 additions & 2 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import React, { setGlobal } from "reactn";

import { TutorialApp } from "../components/app";

/*
Initialize global state here. If you change the object's structure, such
as adding new key value pairs pairs in the object, you will also have to
modify the types/shape for the global object in src/global.d.ts to
reflect the global state object you have here.
*/
setGlobal({
step: 1
tutorialName: "Hello Data",
tutorialStep: 1
});

const IndexPage = (): JSX.Element => <TutorialApp />;
Expand Down

0 comments on commit 1ae0b8a

Please sign in to comment.