typescriptchakra-uireact-tsx

TypeScript Error: Property 'above' does not exist on type 'ShowProps' in Chakra UI


I'm following a tutorial that uses Chakra UI, and the following code works perfectly in the tutorial. However, in my project, I get a TypeScript error on the above prop in the Show component:

import { Grid, GridItem, Show } from "@chakra-ui/react"


function App() {
  return <Grid templateAreas={{
    base: `"nav" "main"`,
    lg: `"nav nav" "aside main"`,
  }}>
    {/* some other components */}
    <Show above="lg">
        <GridItem area="aside" bg="gold">
            Aside
        </GridItem>
    </Show>
  </Grid>
}

export default App

the error message reads: Type '{ children: Element; above: string; }' is not assignable to type 'IntrinsicAttributes & ShowProps<unknown>'. Property 'above' does not exist on type 'IntrinsicAttributes & ShowProps<unknown>'

i use @chakra-ui/react@3.0.2


Solution

  • Based on document of chakra-ui above prop has been removed in version 3

    if you want to use this props, you should install version 2 using

    npm i @chakra-ui/react@2.10.3
    

    you can see the documents for version 2 using chakra-ui-v2 docs

    you can always install older versions of a package using this pattern

    npm install <package>@<version>