I'm new to React and everything is painful, especially understanding the docs that are designed for pros w/ years of experience.
My Problem : The react-avatar-editor https://github.com/mosch/react-avatar-editor gives a list of the available "props", and this is what I need help with. I have a UI but I don't understand how to add logic to it. I know I don't need to write all my own functions. That is the purpose of using a package like this. But I do really need help understanding the concise documentation.
My CODE: not doing anything amazing, but it is constructed in that way that I thought code would work, with the state set, and then I would need functions, like handleScale()
, which I don't know how to write yet, to .setState and change the state. Obviously I'd need one of these for every property.
class MyEditor extends React.Component {
constructor(props){
super(props);
this.state = {
width: 250,
height: 250,
border: 50,
color: [255, 255, 255, 0.6],
scale: 1.2,
rotate: 0,
};
}
handleScale(scale){
this.setState({
scale:"some function that changes the scale"
})
}
render () {
return (
<div className="image-editor-container">
<AvatarEditor
image={this.props.url}
width={this.state.width}
height={this.state.height}
border={this.state.border}
color={this.state.color} // RGBA
scale={this.state.scale}
rotate={this.state.rotate}
/>
<div className="range-slider">Zoom:
<input type="range" onChange={this.state.handleScale}/>
</div>
</div>
)
}
}
But the docs have a list of Props and a listing of what they do. How do I change the scale with a Prop? This might be a ridiculous question, but I'm trying to understand some docs that are above my head and could use any help.
I could also use help hooking up an a slider to change the size of the image. Whether it be state or props- this is basic JS I think but still, I'm not sure of the procedure. In the React Dev Tools the slider moves up and down as props. http://mosch.github.io/react-avatar-editor/docs/
Before posting here I searched everywhere for a tutorial on this subject, editing images in React. If anyone knows of any, or any tutorials re: this package, please direct me there!