Skip to content

Commit

Permalink
simplify example
Browse files Browse the repository at this point in the history
  • Loading branch information
barelyhuman committed Oct 7, 2022
1 parent 10673b4 commit a74b214
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,30 @@ import { Component, h, render } from 'preact'
let document

function App({ rootTag }) {
// Register native components as dom compatible elements
registerNativeDOM()
// create a dom with the root container from react native
document = createDOM(rootTag)
global.document = document
onRender()
// render a preact component to the above DOM
render(h(RenderableComponent, {}), document)
return null
}

function onRender() {
try {
const jsx = h(RenderableComponent, {})
render(jsx, document)
} catch (err) {
console.log(err)
}
}

class RenderableComponent extends Component {
state = {
count: 0,
}

componentDidMount() {
setInterval(()=>{
this.setState({ count: this.state.count + 1 })
},1000)
setInterval(() => {
this.setState({ count: this.state.count + 1 })
}, 1000)
}

render() {
return h('Text', {}, `Count ${this.state.count}`)
return h('SafeAreaView', {}, h('Text', {}, `Count ${this.state.count}`))
}
}

export default App
export default App

0 comments on commit a74b214

Please sign in to comment.