Answer the question
In order to leave comments, you need to log in
How to organize the interaction of several components in React js?
Greetings!
There is an application:
import React from 'react';
import Point from './point';
import Line from './line';
function App() {
return (
<div className="App">
<Point />
<Line />
</div>
);
}
export default App;
class Line extends Base {
render() {
return (
<button>
Линия
</button>
);
}
}
class Point extends Base {
render() {
return (
<button>
Точка
</button>
);
}
}
import React from 'react';
class Base extends React.Component {
constructor(props){
super(props);
this.state = {isToggleOn: true};
}
render(){
return (
<input/>
)
}
}
export default Base;
Answer the question
In order to leave comments, you need to log in
function App() {
const [current, setCurrent] = React.useState(null)
return (
<div className="App">
<Point disabled={current !== 'Point'} onClick={() => setCurrent('Point')} />
<Line disabled={current !== 'Line'} onClick={() => setCurrent('Line')} />
</div>
);
}
class Line extends Base { // какой еще Base?
render() {
return (
<button disabled={this.props.disabled} onClick={this.props.onClick}>
Линия
</button>
);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question