Skip to content

Commit

Permalink
refactor: remove unnecessary storing of props in local state
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardo committed Nov 18, 2024
1 parent 3487a16 commit 64147ae
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/PluginWrapper.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { DashboardPluginWrapper } from '@dhis2/analytics'
import { debounce } from 'lodash/fp'
import React, { useEffect, useLayoutEffect, useState } from 'react'
import React, { useLayoutEffect, useState } from 'react'
import { Plugin } from './components/plugin/Plugin.js'
import './locales/index.js'

const PluginWrapper = (props) => {
const [propsFromParent, setPropsFromParent] = useState(props)
const [renderId, setRenderId] = useState(null)

useEffect(() => setPropsFromParent(props), [props])

useLayoutEffect(() => {
const updateRenderId = debounce(300, () =>
setRenderId((renderId) =>
Expand All @@ -23,7 +20,7 @@ const PluginWrapper = (props) => {
}, [])

return (
<DashboardPluginWrapper {...propsFromParent}>
<DashboardPluginWrapper {...props}>
{(props) => <Plugin id={renderId} {...props} />}
</DashboardPluginWrapper>
)
Expand Down

0 comments on commit 64147ae

Please sign in to comment.