I’m currently having trouble with the phone component I’m writing. To be extra vague about it, on my onChange
, I’m using a function to move to the next text box. However, when I use my data handler function to raise the value to the parent, it doesn’t work. In addition, by adding my data handler to the individual text boxes, it breaks my next Box function.
//dataHandler => raises state data to parent
//nextBox => moves focus to next text box
//onChange should be here
{
dataHandler(dataProp, e);
nextBox(1);
} />
In the code above, either nextBox works alone, or if I add my handler, then neither work.
I’m also wondering about practices. On other forms, I put this type of handler on single boxes, and it works fine. Since my phone input component has multiple boxes, I’m thinking that onChange won’t work exactly the same regardless.
Any advice, tips, or need to know info?
Ps: I’m on mobile, so I greatly simplified the code I’m using, and the formatting is wonky. Assume that there’s an onChange before the brackets with an (e) =>. My app or lemmy is deleting it on submission.
Hey, I’m just now seeing this. So, my component hierarchy is something like this:
App
The TextInput components are very simple:
import { ErrorMessage } from "../ErrorMessage"; //this function can be used to determine if the error message renders based on criteria export const FunctionalTextInput = ({ dataProperty, errorMessage, placeholder, value, propertyHandler, }: { dataProperty: string; errorMessage: string; placeholder: string; value: string; propertyHandler: (property: string, e: string) => void; }) => { //Object.keys(initialUserData)[0] return ( <> <div> {dataProperty}: propertyHandler(dataProperty, e.target.value)} /> </div> ); };
The shape of my data is like so:
In my Form Component, I have two functions that work in the TextInput component, but not the PhoneInput component.
So, over the past few hours I’ve been trying to talk to bing about this, and get some answers. After a few hours, I finally think the problem is a conflict of state. It seems like the state I’m using in my PhoneInput component interferes with the state of the parent component. This seems to be the case since when I click submit, my dataHandler function doesn’t trigger for the PhoneInput component.
So, I guess now I’m wondering how that works? I’ve heard of raising state to the parent, but passing state down, not as data, but as actual state, sounds difficult and somewhat complex. I’m wondering how to use this technique, the uses, and how I can determine when to use it. Or, better yet, maybe I’m missing something and the answer is right outside my reach.
The phone input in question:
Please note that this component is 1000% broken. I was in the process of changing it with Bings suggestions, but it’s frustrating getting anything useful out of the thing.