cjmling / findings

Notes on stuff i finds worth keeping for quick reference later on.
2 stars 0 forks source link

Type string and export #315

Open cjmling opened 2 years ago

cjmling commented 2 years ago

Export type typescript example multiple string option

chandu.js

export type FilterBy =
  | 'total_value_locked'
  | 'apy'
  | 'liquidity'
  | 'type'
  | undefined

interface filterContext {
  filterBy: FilterBy
}

const context: filterContext = {
  filterBy: undefined,
}

export const FilterContext = React.createContext(context)

bandu.js

import { FilterBy, FilterContext } from './filter-advance-context'

 const [filterBy, setFilterBy] = useState<FilterBy>(filterState.filterBy)

So basically we can declare using type and export it.

Then in other file we can import and use it as type

type string multiple option string

cjmling commented 2 years ago

You may also import the object and use as typeof in this example it can be useState<typeof filterState.filterBy>(filterState.filterBy)