Skip to content

Commit

Permalink
feat(react): 新增 useEnvironment
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Jul 24, 2020
1 parent 6e09372 commit 7db160e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/react/__snapshots__/useEnvironment.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`useEnvironment 表现正常 1`] = `
Object {
"android": false,
"browser": true,
"deno": false,
"ios": false,
"miniProgram": false,
"nodejs": true,
"taro": false,
"wechatMiniProgram": false,
"wechatWebView": false,
}
`;
1 change: 1 addition & 0 deletions src/react/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export * from './isVisibleValue'
export * from './renderComponent'
export * from './useClassName'
export * from './useControllableValue'
export * from './useEnvironment'
export * from './useLoadMore'
export * from './useReachBottom'
export * from './useScrollLoadMore'
Expand Down
9 changes: 9 additions & 0 deletions src/react/useEnvironment.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { renderHook } from '@testing-library/react-hooks'
import { useEnvironment } from './useEnvironment'

describe('useEnvironment', () => {
test('表现正常', () => {
const { result } = renderHook(() => useEnvironment())
expect(result.current).toMatchSnapshot()
})
})
11 changes: 11 additions & 0 deletions src/react/useEnvironment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getEnvironment, GetEnvironmentResult } from '../utils'
import { useMemo } from 'react'

/**
* 获取运行环境信息。
*
* @returns 返回运行环境信息
*/
export function useEnvironment(): GetEnvironmentResult {
return useMemo(getEnvironment, [])
}

0 comments on commit 7db160e

Please sign in to comment.