0
0
0348raven2016-04-11 14:45:37
flux
0348raven, 2016-04-11 14:45:37

How to make a dropdown block on click (React Redux)?

class CompanyPage extends React.Component {
    static propTypes = {
        dispatch: PropTypes.func.isRequired
    };

constructor(props) {
        super(props);

        this.state = {
            info: {
                display: 'none !important'
            }
        };
    }

onBtnClickHandler(e) {
    e.preventDefault();

        var block = document.querySelector('.selected-company-info__text');

        block.setState({
            info: { display: 'block !important' }
        });

    }

render () {
        const {
            props: {   },
            state: { info }
            } = this;

const style = {
            info: {
                block: info.block
            }
        };

return(
<a
                        href="javascript://"
                        className="button button--white button--center"
                        onClick={this.onBtnClickHandler}>
                        УЗНАТЬ БОЛЬШЕ О ...
                    </a>
                </div>
                <div style={style.block} className="selected-company-info__text visible-tablet disable-mobile">
                    some text
                </div>
);

}

}

export default CompanyPage;

I give an example of a component, I am just starting to learn redux, so there may be various kinds of errors. I ask you to point them out and give an example of another implementation of this moment.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Izmailov, 2016-04-11
@WapGeaR

Oh lord.

componentWillMount() {
this.setState({buttonToggle: true})
}

handleClick() {
this.setState({buttonToggle: !this.state.buttonToggle})
}

render() {
.....
<div style={{display: (this.state.buttonToggle ? 'block' : 'none')}}></div>
....
}

Ну и собственно зачем document.querySelector там где это не надо и вложенность стилей странная у вас, запутаетесь же

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question