mirror of
https://github.com/morten-olsen/react-native-debug-console.git
synced 2026-02-08 00:36:26 +01:00
init
This commit is contained in:
43
lib/src/components/data/Log.js
Normal file
43
lib/src/components/data/Log.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import { Component } from 'react';
|
||||
import log from '../../log';
|
||||
|
||||
class Log extends Component {
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
logs: [],
|
||||
};
|
||||
this.addLog = this.addLog.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
log.listen(this.addLog);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
log.unlisten(this.addLog);
|
||||
}
|
||||
|
||||
addLog(entry) {
|
||||
entry = Array.isArray(entry) ? entry : [entry];
|
||||
const logs = [
|
||||
...this.state.logs,
|
||||
...entry,
|
||||
];
|
||||
this.setState({
|
||||
logs,
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
children,
|
||||
} = this.props;
|
||||
const component = children(
|
||||
this.state,
|
||||
);
|
||||
return component;
|
||||
}
|
||||
}
|
||||
|
||||
export default Log;
|
||||
Reference in New Issue
Block a user