ProductiveRage / Bridge.React

Bindings for Bridge.NET for React - write React applications in C#!
MIT License
74 stars 14 forks source link

Component children don't have their '_reactElement' key set due to Bridge 16 casing #26

Closed Porl91 closed 7 years ago

Porl91 commented 7 years ago

If I upgrade to Bridge 16 / Bridge.React 2.4.0 then when inspecting 'i' in the example below, the '_reactElement' property 'key' isn't set. If I make the 'Key' property in the Props class lowercase this appears to resolve the issue.

[Ready]
public static void Main()
{
    var i = Enumerable.Range(0, 10).Select(x => new TestComponent(x.ToString())).ToArray();
    //@ debugger
}
public class TestComponent : PureComponent<TestComponent.Props>
{
    public TestComponent(string key) : base(new Props(key)) { }
    public override ReactElement Render() => null;
    public class Props : IAmImmutable
    {
        public Props(string key)
        {
            this.CtorSet(_ => _.Key, key);
        }
        public string Key { get; }
    }
}
ProductiveRage commented 7 years ago

A couple of tips that are totally unrelated to this issue:

  1. If you have a "public static void Main" method then Bridge seems to automatically start it after the scripts are all loaded, you don't need a [Ready] attribute
  2. You can use "Script.Debugger();" instead of dropping into JavaScript - just allows the compiler to catch typos (I don't know why but my fingers often try to type "debubber")
  3. If you want to follow the classes-shouldn't-be-unsealed-by-default (and you would surely be bananas not to!) then the public ProductiveRage.SealedClassVerification.Bridge NuGet package has an analyser to help - more details available at github.com/ProductiveRage/ProductiveRage.SealedClassVerification
ProductiveRage commented 7 years ago

An updated version (2.5.0) is being indexed in nuget.org currently and should be available soon.