首页 > 代码库 > [PReact] Create a Hello World App with Preact
[PReact] Create a Hello World App with Preact
By creating a simple ‘hello world’ example application first in vanilla Javascript, and then in Preact without any tools, we’ll learn what type of problems Preact is solving for us and how is works at a low level. Then we’ll switch to a Webpack + Babel setup we’ll cover some fundamental concepts such as, which imports we need, how to create a component, how to use JSX and finally how to render our component into a target element in a web page.
index.js
import {h, render} from ‘preact‘;import App from ‘./components/App‘;render(<App />, document.querySelector(‘main‘));
Here, we must import ‘h‘ even we don‘t use it. It allows preact convert JSX to JS render to the DOM.
App.js:
import {h} from ‘preact‘;const App = () => { return ( <div> Hello World!!! </div> );};export default App;
[PReact] Create a Hello World App with Preact
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。