0

I have the problem when I use the Reactjs, I'm really new to Reactjs, so maybe it's a easy problem I want to use the class ClickButton in the UserInfo,but I don't know how to change the name through props

import React, { PropTypes } from 'react';
import { Button } from 'antd';
import { connect } from 'react-redux';
import styles from './ClickButton.less';

const ClickButton = ({ todos,dispatch }) => {

  const userinforclick = () => {
  dispatch({
      type: 'todos/clickbutton',
      payload: !todos['click_button'],
  });
};

return (
  <span>
      < span type="primary" className={ styles.show }  onClick={     userinforclick.bind(this) } > {this.props.name} < /span >  
  </span>
);

};

function clickbutton({ todos }){ return{ todos:todos, } }

export default connect(clickbutton)(ClickButton) and i use the ClickButton in UserInfo: import React from 'react' import styles from './Userinfo.less' import ClickButton from '../../components/Button/ClickButton' import { connect } from 'react-redux'; import { Spin } from 'antd'

const Userinfo = ({ todos,dispatch }) => {
const { userinfo, userinfoloading, click_button } = todos;

if(userinfoloading) {
  return <Spin />;
}
const renderList = () => {
    return(
        <div className={ styles.userInfodiv}>
            <div>
                <span className={ styles.userInfoTitle }>userinfo</span>
            </div>
            <div className = { styles.slice }></div>
            <div className = { styles.userInfoBody}>
                <div className = { styles.userInfoSubBody }>
                    <span>username:</span>
                    <span>{userinfo[0]['username']}</span>
                </div>
                <div  className = { styles.userInfoSubBody }>
                    <span>number:</span>
                    { click_button ? <span>{userinfo[0]['phone']}</span>  : <input type="text" value={userinfo[0]['phone']} /> }

                    <ClickButton name="john" />
                </div>
            </div>

        </div>
    );
};
return (
    <div>
        { renderList() }
    </div>
);
};

function mapStateToProps({ todos }) {
  return {
    todos: todos,
  };
}

export default connect(mapStateToProps)(Userinfo);
5
  • You should use classes for your components like this instead of the function syntax. ie,class renderList extends React.Component Commented Aug 5, 2016 at 2:28
  • 1
    Reactjs -> react implemented in JS. Reacths -> react implemented in Haskell. Finally! :-) Commented Aug 5, 2016 at 2:57
  • I use the class,but it still have the problem Commented Aug 5, 2016 at 3:19
  • changing to class wont solve the problem, its just the syntax. where are you passing props to renderList? Commented Aug 5, 2016 at 7:51
  • I define it as the Class button,and I use the button: <button name = "john">。 Commented Aug 9, 2016 at 2:13

1 Answer 1

0

Here's something that actually works (although I removed the todos and such but you can add them in easily):

class RenderList extends React.Component {
  render() {
    return (<span> {this.props.name} </span>);
  }
}

class App extends React.Component {
  render() {
    return (<div>
      <RenderList name="John"/>
    </div>)
  }
}

ReactDOM.render(<App/>,document.getElementById("app"));
Sign up to request clarification or add additional context in comments.

3 Comments

I show the complete code,can you tell me,why I there;s the bug
I think you should post the full code. I see that you have edited your post to add some more code, but I doubt it even compiles properly. You are better off posting the full code to get better help.
this what i define the clickbutton and use it as a component

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.