jtgi
jtgi
TTCTheo's Typesafe Cult
Created by jtgi on 11/18/2022 in #questions
react - submitting form from parent or sibling
hey all, I am struggling to implement a design that has the submit button for a form essentially in the parent. the markup essentially boils down to something like:
div
menubar
form
div
menubar
form
A button in the menu bar can submit the form, and it should be disabled if the form is dirty, etc. I’m achieving the submission via passing a ref. Which feels hacky. But I can’t get “is dirty?” and other form lifecycle events easily. I also don’t want to pull up the state because menubar is reasonably far up in the tree and I want the form to be reusable in different places or with different actions. Any patterns for doing this well? I’m using Formik if it matters.
10 replies
TTCTheo's Typesafe Cult
Created by jtgi on 10/31/2022 in #questions
useEffect deps for run on mount
given an effect you want to run on mount like:
const publish = () => {…}

useEffect(() => {
publish();
//…
}, []);
const publish = () => {…}

useEffect(() => {
publish();
//…
}, []);
exhaustive deps lint rule requires listing publish. So I have to override or memoize functions and other vars used in context. Is there a reason the linter still tries to enforce this? Just consistency?
2 replies