Skip to content

Basic Arithmetic in React

License

Notifications You must be signed in to change notification settings

SivanMehta/react-arithmetic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-arithmetic

npm (scoped) GitHub Build Status

A horrible substitute for actual math by (ab)using React instead

Usage

npm install react-arithmetic

There are two operations you can perform out of the box Add and Multiply. You can then use these on a Number to render an arithmetic operation

So you if you wanted to represent 2 * 2 * (1 + 2 + 2), you can do it as follows

import React, { Component } from 'react';
import { Number, Add, Multiply } from 'react-arithmetic';

class Mathemagic extends Component {
  render() {
    return (
      <Multiply>
        <Number value={ 2 } />
        <Number value={ 2 } />
        <Add>
          <Number value={ 1 } />
          <Number value={ 2 } />
          <Number value={ 2 } />
        </Add>
      </Multiply>
    );
  }
}

This will resolve 20

Tests

npm test