score:1
you can rewrite the field component for address accordingly.
<field name="address">
{({
field, // { name, value, onchange, onblur }
}) => {
values.address = values.mainaddress;
return (
<div>
<input
{...field}
type="text"
placeholder="address"
/>
</div>
);
}}
</field>
here we are setting the value of address field to values.mainaddress if setadress checkbox is checked else we let formik value to fill it.
here is the working codesandbox code - https://codesandbox.io/s/fervent-tereshkova-sro93?file=/index.js
score:1
formik also provides values object you could use that for updating address value same as mainaddress. just provide name attribute to both input fields then assign like this - props.values.address = {...props.values.mainaddress}
Source: stackoverflow.com
Related Query
- Set the value of a form based on state in React
- How can I set the default state of a checkbox based on value in firestore in react table
- How to submit a form with radio buttons in react and increment the state by one based on the value submitted?
- How to set the initial state value after fetching data to update a form in react
- How to set react state to some initial state based on the value of formfield using react and typescript?
- How to set initial state value in Gatsby based on the result from static query?
- Unable to set the value of a variable to state variable in react js
- Using a single handler function to set the state of inputs in a form in React
- in React i need to get the state from local storage and then set another state conditionally based on this state
- React - How to use the current state value as a variable so i can set as a index inside an array
- Filtering Json data based on key and assiging the value to state in react
- How to set the initial state in React based on a Rx.ReplaySubject model
- Which component life cycle method to use to set the state based on the prop value changes
- How to set State in React for different scenarios based on the data that is available?
- how can I set the reducer's return value to state object in component in react js
- Simple bind of the value of this to equal this in the upper scope in React to set the state
- How do I use React setState() to set the state to a specific value that is a constant?
- Access the updated value after Set state in React
- How to filter React state based on the value of 3 select dropdowns?
- React hooks to update state based on the previous state value
- Can I avoid submission of a React form before the state of all controlled fields was set
- Why does React rerender when the state is set to the same value the first time via an onClick event on DOM, but not react-native?
- How to set the value of form field based on another form field using react, typescript and formik?
- How to set the field2 and field3 to required based on the field1 value in react
- React initial renders null value but updates later. Need to set the value as initial state
- How can I change the state of one React component based on the value of its sibling?
- how to fetch data in react based on the state value
- How can I change the value of an object in react based on form data input by the user?
- Trying to set initial state of a react component based on the data I receive from an api call
- React – the right way to pass form element state to sibling/parent elements?
More Query from same tag
- React Maximum Depth Exceeded (Unknown Reason)
- Array push not working inside promise then?
- Laravel and react, How to give a notification from Laravel to my react application (Unexpected use of 'self' no restricted-globals error)
- How to properly export a component from a React custom hook and a function to control it?
- Trying to create a dropdown selection menu with React's <select> and map users from an array as an option
- How can conditionally render some text in React without using an else branch?
- Versioning bundle file
- Why aren't my stylesheets being included in the Webpack build?
- justify content space between wont show a div
- State not being changed
- Read data from request which just finished
- Radio button select issue, while using Map function
- How to change props object name when it's clicked in react?
- Why can't I call a React hook from this functional component?
- How do you manage component dependency order with Facebook React?
- How can I extract key values form my JSON dictionary?
- Node server gives me undefined when I send data
- Reset Redux-Form after server response
- Cannot Pass Props to another component in React Native
- Action creator in not dispatching an action
- Sort the tags content by mobile & desktop breakpoint
- ReactJS - How to properly initialize state from props which is populated by fetching data?
- State seems to be getting overwritten instead of merged
- How to reset useState everytime I change my page?
- REACT and WebAPI CORS policy issue
- ReactJS - multiline textarea
- I can't get the data of the user by his id
- find multiple fields from an array in mongodb
- How to keep user's (not my) API tokens securely?
- npx-create-react-app my-app command ERROR in Vs Code