The example below will throw a warning that someState
should be included in the dependency array of the useEffect
, however I do not wish for changes to someState
to trigger the useEffect
to run.
So, how do I make sure that the function runs on updates to someTrigger
while running with an updated version of someState
?
import React, { useState, useEffect } from 'react'
function someFunction() {
const [someTrigger, setSomeTrigger] = useState(null)
const [someState, setSomeState] = useState({})
useEffect(() => {
async function postSomething() {
const response = await fetch('somePath',
method: 'POST',
body: JSON.stringify(someState),
})
...
}
postSomething()
} [someTrigger])
return <SomeComponent />
}