Coyote is a react-like javascript UI library. It is very lightweight. Here is a brief comparison. A real example is at here. You can see a live demo at codesandbox.
More Examples:
- Pure javascript code, no jsx!
- Very lightweight, only less than 300 lines of code! Please checkout github
- live demo at codesandbox.
- Mixture of jsx and javascript
- Lots of code. Please checkout github
Example:
MyComponent(
child1,
child2
)
Example:
<MyComponent>
child1
child2
</MyComponent>
Example:
MyComponent({x=1, y=2},
child1,
child2
)
Example:
<MyComponent x={1} y={2}>
child1
child2
</MyComponent>
Example:
import { H1, DIV, P, BUTTON } from "coyote2";
Not needed, jsx transpiler import those html tags implicitly.
Example:
const MyPage = componentFactory(class MyPage extends Component {
state = {
count: 0,
}
clickHandler = () => {
this.setState(state => {state.count +=1;});
}
render() {
return DIV(
P({style: 'color:red;'}, `Clicked ${this.state.count} times`),
BUTTON({onclick: this.clickHandler},
">> click me <<"
)
);
}
});
Example:
class MyPage extends React.Component {
state = {
count: 0,
}
clickHandler = () => {
this.setState({count: this.state.count+1})
}
render() {
return <div>
<p style={'color:red;'}>`Clicked ${this.state.count} times`</p>,
<button onclick = {this.clickHandler}>
{">> click me <<"}
</button>
</div>;
}
}
Example:
// use immer producer so you can modify state, while state property is still immutable
this.setState(state => {state.count += 1});
Example:
// Create a new state and pass it to setState
this.setState({count:state.count+1});