|
| 1 | +# React# |
| 2 | + |
| 3 | +## ReactSharp - A C# library for building web user interfaces |
| 4 | +[](https://www.nuget.org/packages/ReactSharp.Blazor/) |
| 5 | +[](https://gitter.im/MatBlazor/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) |
| 6 | +[](https://github.com/SamProf/ReactSharp/stargazers) |
| 7 | +[](https://github.com/SamProf/ReactSharp/issues) |
| 8 | +[](https://reactsharp.samprof.com) |
| 9 | +[](LICENSE) |
| 10 | +[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9XT68N2VKWTPE&source=url) |
| 11 | +[](https://www.patreon.com/SamProf) |
| 12 | + |
| 13 | + |
| 14 | +## Demo and Documentation |
| 15 | +- [http://reactsharp.samprof.com](http://reactsharp.samprof.com) |
| 16 | + |
| 17 | + |
| 18 | +## Examples |
| 19 | + |
| 20 | +### Counter.cs |
| 21 | +```csharp |
| 22 | + public class Counter : ReactComponent |
| 23 | + { |
| 24 | + private int value = 0; |
| 25 | + |
| 26 | + void Increment() |
| 27 | + { |
| 28 | + SetState(() => { value++; }); |
| 29 | + } |
| 30 | + |
| 31 | + void Decrement() |
| 32 | + { |
| 33 | + SetState(() => { value--; }); |
| 34 | + } |
| 35 | + |
| 36 | + |
| 37 | + public override object Render() |
| 38 | + { |
| 39 | + return new ReactElement($@" |
| 40 | +<div> |
| 41 | + <h4>Counter value: {value}</h4> |
| 42 | + <p> |
| 43 | + <button type='button' class='btn btn-primary' onclick='{new Action(Increment)}'>Increment</button> |
| 44 | + <button type='button' class='btn btn-primary' onclick='{new Action((Decrement))}'>Decrement</button> |
| 45 | + </p> |
| 46 | +</div> |
| 47 | +"); |
| 48 | + } |
| 49 | + } |
| 50 | +``` |
| 51 | + |
| 52 | +### App.cs |
| 53 | +```csharp |
| 54 | + public class App : ReactComponent |
| 55 | + { |
| 56 | + public override object Render() |
| 57 | + { |
| 58 | + return new ReactElement($@" |
| 59 | +<Fragment> |
| 60 | +
|
| 61 | + <p style='padding-top: 20px;'> |
| 62 | + <Counter /> |
| 63 | + </p> |
| 64 | +
|
| 65 | +</Fragment> |
| 66 | +"); |
| 67 | + } |
| 68 | + } |
| 69 | +``` |
| 70 | + |
| 71 | + |
| 72 | +### Index.razor |
| 73 | + |
| 74 | +```html |
| 75 | +<ReactSharpBlazor Prerender="true" Element="@_reactElement"></ReactSharpBlazor> |
| 76 | + |
| 77 | +@code |
| 78 | +{ |
| 79 | + ReactElement _reactElement = new ReactElement($@"<App/>"); |
| 80 | +} |
| 81 | +``` |
| 82 | + |
| 83 | + |
| 84 | +### Todo.cs [In action](http://reactsharp.samprof.com/Todo) |
| 85 | +```csharp |
| 86 | + public class Todo : ReactComponent |
| 87 | + { |
| 88 | + List<string> items = Enumerable.Range(0, 10).Select(i => i.ToString()).ToList(); |
| 89 | + |
| 90 | + |
| 91 | + void Add() |
| 92 | + { |
| 93 | + SetState(() => { this.items.Add(Guid.NewGuid().ToString()); }); |
| 94 | + } |
| 95 | + |
| 96 | + |
| 97 | + void Remove(string item) |
| 98 | + { |
| 99 | + SetState(() => { this.items.Remove(item); }); |
| 100 | + } |
| 101 | + |
| 102 | + |
| 103 | + public override object Render() |
| 104 | + { |
| 105 | + return new ReactElement($@" |
| 106 | +<div> |
| 107 | + <h4>Todo: {items.Count}</h4> |
| 108 | + <p> |
| 109 | + <button type='button' class='btn btn-primary' onclick='{new Action((Add))}'>Add item</button> |
| 110 | + </p> |
| 111 | + {items.Select(i => new ReactElement($"<div>Task - {i} <button onclick='{new Action(() => Remove(i))}'>X</button></div>"))} |
| 112 | + |
| 113 | +</div> |
| 114 | +"); |
| 115 | + } |
| 116 | + } |
| 117 | +``` |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | +## News |
| 124 | + |
| 125 | +### ReactSharp 1.0.0 |
| 126 | +- First public release |
| 127 | + |
| 128 | + |
| 129 | +## Prerequisites |
| 130 | + |
| 131 | +Don't know what Blazor is? Read [here](https://github.com/aspnet/Blazor) |
| 132 | + |
| 133 | +Complete all Blazor dependencies. |
| 134 | + |
| 135 | +- .NET Core 3.1 |
| 136 | +- Visual Studio 2019 with the ASP.NET and web development workload selected. |
| 137 | + |
| 138 | +## Installation |
| 139 | + |
| 140 | +Latest version in here: [](https://www.nuget.org/packages/ReactSharp.Blazor/) |
| 141 | + |
| 142 | + |
| 143 | +To Install |
| 144 | + |
| 145 | +``` |
| 146 | +Install-Package ReactSharp |
| 147 | +Install-Package ReactSharp.Blazor |
| 148 | +``` |
| 149 | + |
| 150 | +For client-side and server-side Blazor - add script section to index.html or _Host.cshtml (head section) |
| 151 | + |
| 152 | +```html |
| 153 | +<script src="_content/ReactSharp.Blazor/react-sharp.js"></script> |
| 154 | +``` |
| 155 | + |
| 156 | + |
| 157 | +## Questions |
| 158 | + |
| 159 | +For *how-to* questions and other non-issues, for now you can use issues or you can use [](https://gitter.im/MatBlazor/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge). |
| 160 | + |
| 161 | + |
| 162 | +## Contributing |
| 163 | +We'd greatly appreciate any contribution you make. :) |
| 164 | + |
| 165 | +## Sponsors & Backers |
| 166 | +ReactSharp does not run under the umbrella of any company or anything like that. |
| 167 | +It is an independent project created in spare time. |
| 168 | + |
| 169 | +If you think that this project helped you or your company in any way, you can consider becoming a backer/sponsor. |
| 170 | +- [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9XT68N2VKWTPE&source=url) |
| 171 | +- [Patreon](https://www.patreon.com/SamProf) |
| 172 | + |
| 173 | + |
| 174 | + |
| 175 | +## License |
| 176 | + |
| 177 | +This project is licensed under the terms of the [MIT license](LICENSE). |
| 178 | + |
| 179 | +## Thank you |
| 180 | +- [Blazor](https://blazor.net) |
| 181 | + |
0 commit comments