Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag function with state #14

Open
l1zard opened this issue Jun 23, 2020 · 1 comment
Open

Drag function with state #14

l1zard opened this issue Jun 23, 2020 · 1 comment

Comments

@l1zard
Copy link

l1zard commented Jun 23, 2020

How to use drag function with state? But when i use on move function i am guessing object will rerender and onmove is fired only once (checked with console.log). How to used it properly?

state = {
    x: 10,
    y: 10
}


onstart = (x, y) => {
    this.setState({x: x, y: y})
}

onMove = (dx, dy) => {
    let x = this.state.x;
    let y = this.state.y
    this.setState({x: x + dx, y: y + dy})
}


end = (x, y) => {
    this.setState({x: x, y: y})
}

render() {
    return (
        <div className="design_wrapper">
            <div className="svg_container">
                <Paper width={300} height={300}>
                    <Set>
                        <Circle key={"asdd"} x={this.state.x} y={this.state.y} r={15}
                                attr={{stroke: "#000", fill: "#000"}}
                                drag={{
                                    move: this.onMove,
                                    start: this.onstart,
                                    end: this.end
                                }}/>
                    </Set>
                </Paper>
            </div>
        </div>
    );
}

}`

@DragonflyCaptain
Copy link

DragonflyCaptain commented Jul 14, 2020

借楼问下 老哥 为什么mousemove和mouseout 会同时执行``

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants