Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Props not converted to camelCase by default #531

Closed
igorroch opened this issue Apr 11, 2018 · 3 comments
Closed

Props not converted to camelCase by default #531

igorroch opened this issue Apr 11, 2018 · 3 comments

Comments

@igorroch
Copy link

igorroch commented Apr 11, 2018

According to #330 json should be converted by default.

But if we use this example
@Html.React("ReactWorld", new { Name = "World" })

it will be rendered as
ReactDOM.hydrate(React.createElement(ReactWorld, {"Name":"World"}),...

Minimal repo to reproduce.

@wub
Copy link

wub commented Apr 13, 2018

That's in .NET Core I believe.

@tachyon1337
Copy link

You need to set up the camelCase behavior in the startup file. Something like

app.UseReact(config => {
        config
            .SetJsonSerializerSettings(new JsonSerializerSettings
            {
                StringEscapeHandling = StringEscapeHandling.EscapeHtml,
                ContractResolver = new CamelCasePropertyNamesContractResolver()
                      
            });
});

@dustinsoftware
Copy link
Member

dustinsoftware commented May 7, 2018

Looks like this is intentional - we won't be able to change this in the source code without breaking existing projects.

JsonSerializerSettings = new JsonSerializerSettings
{
StringEscapeHandling = StringEscapeHandling.EscapeHtml
};

However, in ASP.NET core projects, that behavior is overridden:

// Camelcase JSON properties by default - Can be overridden per-site in "configure".
ReactSiteConfiguration.Configuration.JsonSerializerSettings.ContractResolver =
new CamelCasePropertyNamesContractResolver();
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants