Skip to content

Is this project still maintained? #49

Closed
@kscc25

Description

@kscc25

Excuse me for the words but I just looked around the hooks and saw so many bad practices in your project (mostly about performance) so I wonder whether you still maintain this project or not.

For example, this hook does resubscribe event every time the component renders. There is a fix here but for maybe some reasons it is merged yet: #38

src/useAppState.ts

import React, { useEffect, useState } from 'react'
import { AppState, AppStateStatus } from 'react-native'

export default function useAppState() {
  const currentState = AppState.currentState
  const [appState, setAppState] = useState(currentState)

  function onChange(newState: AppStateStatus) {
    setAppState(newState)
  }

  useEffect(() => {
    AppState.addEventListener('change', onChange)

    return () => {
      AppState.removeEventListener('change', onChange)
    }
  })

  return appState
}

This hook creates new getPhotos and saveToCameraRoll functions every time the hook is called. It would cause the hook consumer component to rerender unexpectedly.

src/useCameraRoll.ts

export default function useCameraRoll() {
  const [photos, setPhotos] = useState(initialState)

  async function getPhotos(config = defaultConfig) {
    try {
      const photos = await CameraRoll.getPhotos(config)
      setPhotos(photos)
    } catch (err) {
      console.log('error: ', err)
    }
  }

  async function saveToCameraRoll(tag: string, type?: 'photo' | 'video') {
    try {
      await CameraRoll.saveToCameraRoll(tag, type)
    } catch (err) {
      console.log('error saving to camera roll: ', err)
    }
  }

  return [photos, getPhotos, saveToCameraRoll]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions