Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ritwickdey/react-jsx-templating

A very simple React library for templating syntax in JSX, inspired by Angular (e.g. *ngIf ) :)
https://github.com/ritwickdey/react-jsx-templating

jsx react react-library reactjs syntax templating

Last synced: about 1 month ago
JSON representation

A very simple React library for templating syntax in JSX, inspired by Angular (e.g. *ngIf ) :)

Awesome Lists containing this project

README

        

# React Jsx Templating

> React Jsx Templating is a simple library, inspired by Angular :)

[![NPM](https://img.shields.io/npm/v/react-jsx-templating.svg)](https://www.npmjs.com/package/react-jsx-templating) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) [![Build Status](https://travis-ci.com/ritwickdey/react-jsx-templating.svg?branch=master)](https://travis-ci.com/ritwickdey/react-jsx-templating)

`React Jsx Templating` will give you templating syntax like Angular `*ngIf`

**_Live Example: [Open in Codesandbox](https://codesandbox.io/s/j312l1m2x9)_**

## Install

```bash
npm install --save react-jsx-templating
```

## Usage

- **Use HOC**

```jsx
import withTemplating from 'react-jsx-templating'; //Note: default import
class MyComponent extends Component {
render()
return "foo";
}
}

export default withTemplating(MyComponent);
```

- Use Wrapper HTML tags

```jsx
// Note: named import. There are total 118 Elements
import { Fragment, Div, P, Button, Br, Span } from 'react-jsx-templating';
```

## Syntax

- If-else

```diff
let isEnglish = false;
+
```

- switch-case

```diff
let testValue = 'c';
+


+
A

+
B

+
C

+
No Match

+

```

- for-loop

```diff
let people = [{id: 1, name:'Ritwick'}, {id:2, name:'Akash'}]
+

person.id}>
+ {person =>
{person.name}
}
+

```

## Examples

- **Switch-Case Templating**

```jsx
import React, { useState } from 'react';
import { Div } from 'react-jsx-templating';

function ExampleSwitchCase() {
const [animal, setAnimal] = useState('');
return (


setAnimal(e.target.value)}
/>
Please type!!
}>

woof-woof 🐕

meows meows 🐈

Ops!! No Match!




);
}
```

- **If-Else Templating**

```jsx
import React, { Component } from 'react';
import { Div, Fragment, Button, Br } from 'react-jsx-templating';
import { EnglishNewsPaper, SpanishNewsPaper } from './Components';

class ExampleIfElse extends Component {
state = {
isEngLang: true
};

toogleLanguage = () => {
this.setState(oldState => ({ isEngLang: !oldState.isEngLang }));
};

render() {
const { isEngLang } = this.state;
return (


Hola!>}>
Hello!


Toggle Language

);
}
}
```

- **For Loop**

```jsx
import React from 'react';
import { Div } from 'react-jsx-templating';
import { Article } from './Components';

function ExampleForLoop() {
return (

id}>
{article => }

);
}
```

## What's next ?

- ~~Switch Case~~ (added)
- ~~Loop~~ (added)
- ~~Fragment~~ (added)

## License

MIT © [ritwickdey](https://github.com/ritwickdey)