Sam's Implementation of a simplified React for educational purpose. See the slides I used for Cornell DTI's DevSesh.
The project aims to implement a very primitive version of React for web. It should be simple enough so that I could teach it to an average developer in a software project team in less than two hours.
- Install Yarn.
- Clone the repo.
- Run
yarnin repo roots. It will install all dependencies and compile everything. - Run
yarn workspace demo start
- Install Yarn.
- Clone the repo.
- Run
yarnin repo roots. - Run
yarn workspace sam-react dev. It will watch changes insam-reactand auto re-compile. - In another terminal, run
yarn workspace demo start. Changes insam-reactwill auto refresh your page.
- Native elements: only
<div />,<span />,<a />and<input />- The only prop allowed for
divisclassName. - The only prop allowed for
spanischildren, which must be a string. - The only prop allowed for
aishrefandchildren, andchildrenmust be a string. - The only props allowed for
inputisvalueandonChange
- The only prop allowed for
- Plain text is automatically wrapped in
span. - No support for variable number of children in JSX.
useStatehook- Initializer must be a value instead of a function.
- Returned
setStateonly accepts new values instead of an update function.
useEffecthook- No support for dependency array.
- No support for unmount/update cleanup callback.
In addition to the features that are not supported, the project has these limitations:
- Reconcilator is not very efficient when dealing with children changes.
- The rerender schedular is naive.
- Conditional rendering and other techniques become more awkward to write.
- Zero support for a11y.
- It is not compatible with all the currently available React libraries.
If you use this project in your company's production environment, you should probably promote yourself to customer.
My mini-react does not support all React features. For supported feature listed above, there is no
guarantee that it works as it claims, since the code has not been thoroughly tested. (The only
guarantee is that the demo site somehow works.)