2

I'm new to react and redux and i want to create component which contain two radio buttons so i write something like this:

import React, { PropTypes } from 'react';

const renderCashRadioButtons = currentCashSelector => (
  <form onClick={currentCashSelector}>
    <input
      type="radio"
      name="cash-transaction"
      value="Transcation"
      onChange={value => currentCashSelector(value)}
    />
    <input
      type="radio"
      name="cash-transfer"
      value="Transfer"
      onChange={value => currentCashSelector(value)}
    />
  </form>
);


const CashRadioButtons = ({ currentCashSelector }) => (
  <div className="container">
    {renderCashRadioButtons(currentCashSelector)}
  </div>
);

CashRadioButtons.propTypes = {
  currentCashSelector: PropTypes.func.isRequired
};


export default CashRadioButtons;

currentCashSelector is a function. When i render this it does not seem to work. The value does not change and i'm not seeing the state to be updated. Do you have any ideas?

1
  • I dont think so...i used another radio button component and it worked. But i want to use the default html Commented Mar 16, 2017 at 13:37

1 Answer 1

1
  1. You probably want your radio buttons to have the same name, so that when one is selected, the other is deselected.

  2. It looks like your onChange functions are expecting the value, but they're actually receiving the event.

  3. You likely have unwanted duplication between the onChange on your form, and the ones on your radio buttons.

Possible Solution

  <form onClick={event => currentCashSelector(event.target.value)}>
    <input
      type="radio"
      name="cash-type"
      value="Transaction"
    />
    <input
      type="radio"
      name="cash-type"
      value="Transfer"
    />
  </form>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.