How to use the recoil.useRecoilState function in recoil

To help you get started, we’ve selected a few recoil examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github c-bata / goptuna / dashboard / src / hook.ts View on Github external
export const useStudySummaries = (action: Action): StudySummary[] => {
  const [studySummaries, setStudySummaries] = useRecoilState(
    studySummariesState
  )

  useEffect(() => {
    action.updateStudySummaries(setStudySummaries)
    const intervalId = setInterval(function () {
      action.updateStudySummaries(setStudySummaries)
    }, 10 * 1000)
    return () => clearInterval(intervalId)
  }, [])

  return studySummaries
}
github c-bata / goptuna / dashboard / src / hook.ts View on Github external
export const useStudyDetail = (
  action: Action,
  studyId: number
): StudyDetail | null => {
  const [studyDetails, setStudyDetails] = useRecoilState(
    studyDetailsState
  )

  useEffect(() => {
    action.updateStudyDetail(studyId, studyDetails, setStudyDetails)
    const intervalId = setInterval(function () {
      action.updateStudyDetail(studyId, studyDetails, setStudyDetails)
    }, 10 * 1000)
    return () => clearInterval(intervalId)
  }, [])

  return studyDetails[studyId] || null
}
github c-bata / goptuna / dashboard / src / action.ts View on Github external
export const actionCreator = () => {
  const { enqueueSnackbar } = useSnackbar()
  const [studySummaries, setStudySummaries] = useRecoilState(
    studySummariesState
  )
  const [studyDetails, setStudyDetails] = useRecoilState(
    studyDetailsState
  )

  const updateStudySummaries = (successMsg?: string) => {
    getStudySummariesAPI()
      .then((studySummaries: StudySummary[]) => {
        setStudySummaries(studySummaries)

        if (successMsg) {
          enqueueSnackbar(successMsg, { variant: "success" })
        }
      })
      .catch((err) => {
        enqueueSnackbar(`Failed to fetch study list.`, {
          variant: "error",
        })
github c-bata / goptuna / dashboard / src / action.ts View on Github external
export const actionCreator = () => {
  const { enqueueSnackbar } = useSnackbar()
  const [studySummaries, setStudySummaries] = useRecoilState(
    studySummariesState
  )
  const [studyDetails, setStudyDetails] = useRecoilState(
    studyDetailsState
  )

  const updateStudySummaries = (successMsg?: string) => {
    getStudySummariesAPI()
      .then((studySummaries: StudySummary[]) => {
        setStudySummaries(studySummaries)

        if (successMsg) {
          enqueueSnackbar(successMsg, { variant: "success" })
        }
      })
      .catch((err) => {

recoil

Recoil - A state management library for React

MIT
Latest version published 2 years ago

Package Health Score

67 / 100
Full package analysis