首页 > 解决方案 > 尝试为权重对象创建唯一 ID

问题描述

我正在尝试为构造函数中的权重对象创建唯一 ID(我不能使用任何唯一 ID 库,我只能使用 math.random 函数),然后将其传递给渲染方法。


    constructor(props){

        super(props);

        const localDB = loadState();

        this.state = {

            username: localDB.account,
            PrivateKey: localDB.key,
            author: this.props.author,
            permlink: this.props.permlink,
            expanded: false,
            weight : this.props.weight

        };

        return (  
            <div className="upvote">

                <div id="upVote"><br /><input id="expandVote" type="button" value="Open voting UI" onClick={() => this.expandDropdown()} /></div>  
                { this.state.expanded ? <input id="this.state.weight" defaultValue="10" /> : null } 
                { this.state.expanded ? <button id="pushVote" onClick={() => this.pushVote()}>Push vote</button> : null } 
                { this.state.expanded ? <button id="closeVote" onClick={this.closeDropdown}>Close voting UI</button> : null }                       

            </div>
        )
    }

标签: reactjssteemit

解决方案


推荐阅读