| layout | home |
|---|---|
| title | Preact |
| description | Fast 3kB alternative to React with the same modern API. |
Fast 3kB alternative to React with the same modern API
function Counter() {
const [value, setValue] = useState(0);
return (
<>
<div>Counter: {value}</div>
<button onClick={() => setValue(value + 1)}>Increment</button>
<button onClick={() => setValue(value - 1)}>Decrement</button>
</>
)
}Proudly sponsored by:
가상 DOM 구성 요소를 사용하면 버튼에서 데이터 공급자에 이르기까지 재사용 가능한 모든 것을 쉽게 공유할 수 있습니다. Preact의 디자인은 React 생태계에서 사용 가능한 수천 개의 구성 요소를 원활하게 사용할 수 있음을 의미합니다.
간단한 preact/compat 별칭을 번들러에 추가하면 가장 복잡한 React 구성 요소도 애플리케이션에서 사용할 수 있는 호환성 계층이 제공됩니다.
// --repl
export default class TodoList extends Component {
state = { todos: [], text: '' };
setText = e => {
this.setState({ text: e.currentTarget.value });
};
addTodo = () => {
let { todos, text } = this.state;
todos = todos.concat({ text });
this.setState({ todos, text: '' });
};
render({ }, { todos, text }) {
return (
<form onSubmit={this.addTodo} action="javascript:">
<label>
<span>Add Todo</span>
<input value={text} onInput={this.setText} />
</label>
<button type="submit">Add</button>
<ul>
{ todos.map( todo => (
<li>{todo.text}</li>
)) }
</ul>
</form>
);
}
}
// --repl-after
render(<TodoList />, document.getElementById("app"));
// --repl
export default class Stars extends Component {
async componentDidMount() {
let stars = await githubStars(this.props.repo);
this.setState({ stars });
}
render({ repo }, { stars=0 }) {
let url = `https://github.com/${repo}`;
return (
<a href={url} class="stars">
⭐️ {stars} Stars
</a>
);
}
}
// --repl-after
render(<Stars />, document.getElementById("app"));
React에 대한 경험이 있는지 여부에 따라 별도의 가이드가 있습니다.
가장 적합한 가이드를 선택하세요!