Skip to content

Commit

Permalink
Merge pull request #105 from matthieuauger/useId-fix-react-types
Browse files Browse the repository at this point in the history
Use React 18 types and useId hook for identifiers
  • Loading branch information
mazurroman committed Mar 21, 2024
2 parents 3c09008 + 47c74b6 commit bc5132b
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 28 deletions.
4 changes: 2 additions & 2 deletions components/Editor/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMemo } from 'react'
import { useMemo, useId } from 'react'

import Select, { OnChangeValue } from 'react-select'

Expand Down Expand Up @@ -37,7 +37,7 @@ const EditorHeader = ({ codeType, onCodeTypeChange }: Props) => {
isSearchable={false}
classNamePrefix="select"
menuPlacement="auto"
instanceId="headerSelect"
instanceId={useId()}
/>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion components/layouts/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { PropsWithChildren } from 'react'

import { GoogleAnalytics } from '@next/third-parties/google'
import type { NextPage } from 'next'
import Head from 'next/head'
Expand All @@ -7,7 +9,7 @@ import { getAbsoluteURL } from 'util/browser'
import Footer from './Footer'
import Nav from './Nav'

const HomeLayout: NextPage = ({ children }) => {
const HomeLayout: NextPage<PropsWithChildren> = ({ children }) => {
return (
<>
<Head>
Expand Down
3 changes: 1 addition & 2 deletions components/ui/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import cn from 'classnames'

type Props = {
searchable?: boolean
ref?: ForwardedRef<HTMLInputElement>
rightIcon?: JSX.Element
className?: string
inputClassName?: string
readOnly?: boolean
} & React.ComponentPropsWithoutRef<'input'>
} & React.ComponentProps<'input'>

export const Input: React.FC<Props> = forwardRef(
(
Expand Down
4 changes: 2 additions & 2 deletions context/appUiContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { createContext, useState } from 'react'
import React, { PropsWithChildren, createContext, useState } from 'react'

export enum LogType {
Error,
Expand Down Expand Up @@ -31,7 +31,7 @@ export const AppUiContext = createContext<AppUiContextProps>({
addToConsoleLog: () => undefined,
})

export const AppUiProvider: React.FC = ({ children }) => {
export const AppUiProvider: React.FC<PropsWithChildren> = ({ children }) => {
const [isFullScreen, setIsFullScreen] = useState(false)
const [consoleLog, setConsoleLog] = useState<IConsoleOutput[]>([
{
Expand Down
6 changes: 4 additions & 2 deletions context/cairoVMApiContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { createContext, useState } from 'react'
import React, { PropsWithChildren, createContext, useState } from 'react'

import { IInstruction, ILogEntry } from 'types'

Expand Down Expand Up @@ -74,7 +74,9 @@ export const CairoVMApiContext = createContext<ContextProps>({
removeBreakPoint: noOp,
})

export const CairoVMApiProvider: React.FC = ({ children }) => {
export const CairoVMApiProvider: React.FC<PropsWithChildren> = ({
children,
}) => {
const [sierraCode, setSierraCode] = useState<string>('')
const [casmCode, setCasmCode] = useState<string>('')
const [casmInstructions, setCasmInstructions] = useState<IInstruction[]>([])
Expand Down
9 changes: 7 additions & 2 deletions context/settingsContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import React, { createContext, useEffect, useState } from 'react'
import React, {
PropsWithChildren,
createContext,
useEffect,
useState,
} from 'react'

const LOCAL_SETTINGS_KEY = 'cairovmcodes_settings'

Expand All @@ -23,7 +28,7 @@ export const SettingsContext = createContext<ContextProps>({
setSetting: () => null,
})

export const SettingsProvider: React.FC<{}> = ({ children }) => {
export const SettingsProvider: React.FC<PropsWithChildren> = ({ children }) => {
const [settings, setSettings] = useState<any>({})
const [settingsLoaded, setSettingsLoaded] = useState(false)

Expand Down
16 changes: 9 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"lodash.debounce": "^4.0.8",
"next": "13",
"next-mdx-remote": "^4.4.1",
"next-themes": "^0.0.15",
"next-themes": "^0.1.1",
"process": "^0.11.10",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand All @@ -57,7 +57,7 @@
"@types/js-cookie": "^3.0.1",
"@types/lodash.debounce": "^4.0.6",
"@types/mdx-js__react": "^1.5.5",
"@types/react": "17.0.30",
"@types/react": "^18.2.67",
"@types/react-table": "^7.7.6",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
Expand Down
5 changes: 2 additions & 3 deletions pages/about.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react'
import React, { ReactNode } from 'react'

import type { NextPage } from 'next'
import Head from 'next/head'

import HomeLayout from 'components/layouts/Home'
Expand Down Expand Up @@ -513,7 +512,7 @@ const AboutPage = () => {
)
}

AboutPage.getLayout = function getLayout(page: NextPage) {
AboutPage.getLayout = function getLayout(page: ReactNode) {
return <HomeLayout>{page}</HomeLayout>
}

Expand Down
5 changes: 2 additions & 3 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useContext } from 'react'
import { ReactNode, useContext } from 'react'

import type { NextPage } from 'next'
import Head from 'next/head'

import { AppUiContext } from 'context/appUiContext'
Expand Down Expand Up @@ -37,7 +36,7 @@ const HomePage = () => {
)
}

HomePage.getLayout = function getLayout(page: NextPage) {
HomePage.getLayout = function getLayout(page: ReactNode) {
return <HomeLayout>{page}</HomeLayout>
}

Expand Down
5 changes: 3 additions & 2 deletions pages/playground.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { NextPage } from 'next'
import { ReactNode } from 'react'

import Head from 'next/head'

import Editor from 'components/Editor'
Expand All @@ -25,7 +26,7 @@ const PlaygroundPage = () => {
)
}

PlaygroundPage.getLayout = function getLayout(page: NextPage) {
PlaygroundPage.getLayout = function getLayout(page: ReactNode) {
return <HomeLayout>{page}</HomeLayout>
}

Expand Down

0 comments on commit bc5132b

Please sign in to comment.