Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can this be used with useReducer? #57

Closed
mdodge-ecgrow opened this issue Jan 9, 2020 · 1 comment
Closed

can this be used with useReducer? #57

mdodge-ecgrow opened this issue Jan 9, 2020 · 1 comment

Comments

@mdodge-ecgrow
Copy link

mdodge-ecgrow commented Jan 9, 2020

I have switched my form to the useReducer methodology because it was getting too cumbersome. Now I'm not sure if it is possible to continue using this library or not.

Here is my relavant code:

const initialState = {
	bagID: '',
	lineTechName: '',
	infoCorrect: '',
	materialCorrect: '',
	unwantedMaterials: '',
	unwantedMaterial: '',
	qualityAcceptable: '',
	program: '',
	sealingProperly: '',
	temperature: ''
};

const [userInput, setUserInput] = useReducer(
	(state, newState) => ({ ...state, ...newState }),
	initialState
);

....
const handleChange = (evt) => {
	const { name, value } = evt.target;
	setUserInput({ [name]: value });
};
....
<RadioGroup
	name={'infoCorrect'}
	selectedValue={????}
	// onChange={(value) => {
		// 	setInfoCorrect(value);
	// }}
	onChange={handleChange}
>
<label className={'radio'}>
	<Radio value={'yes'} />
	Yes
</label>
<label className={'radio ml-5'}>
	<Radio value={'no'} />
	No
</label>
</RadioGroup>

I added question marks to the biggest part that I'm unsure about. Also, I am guessing the handleChange logic will need to change because that is for normal text inputs.

@mdodge-ecgrow
Copy link
Author

FYI, for anyone who runs into a similar issue, I figured out how to do this here: #53 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant