Skip to content

Allow control of the container ID #50

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

Closed
jhemminger opened this issue Nov 21, 2014 · 3 comments
Closed

Allow control of the container ID #50

jhemminger opened this issue Nov 21, 2014 · 3 comments

Comments

@jhemminger
Copy link

Hi - I need to be able to control the value of the ID that is currently being generated as "react#" - I thought you may have fixed this as part of #45 but instead that change allows the user to define the element type. Any chance you could include the ability to change the id? I think others would be happy to have this ability as well.

Your code is setup well to allow for this change easily, something like so is all I need:

Addition on the Extension:

public static IHtmlString React(
this HtmlHelper htmlHelper,
string componentName,
T props,
string htmlTag = null,
string htmlId = null
)
{
var reactComponent = Environment.CreateComponent(componentName, htmlId, props);
if (!string.IsNullOrEmpty(htmlTag))
{
reactComponent.ContainerTag = htmlTag;
}
var result = reactComponent.RenderHtml();
return new HtmlString(result);
}

Addition on ReactEnvironment:

public virtual IReactComponent CreateComponent(string componentName, string componentDomId, T props)
{
EnsureUserScriptsLoaded();

if (string.IsNullOrEmpty(componentDomId))
{
_maxContainerId++;
componentDomId = string.Format(CONTAINER_ELEMENT_NAME, _maxContainerId);
}

var component = new ReactComponent(this, _config, componentName, componentDomId)
{
Props = props
};
_components.Add(component);
return component;
}

Thanks!

@Daniel15
Copy link
Member

Thanks, I'll add it this weekend.

Sent from my phone.
On Nov 21, 2014 9:05 AM, "jhemminger" [email protected] wrote:

Hi - I need to be able to control the value of the ID that is currently
being generated as "react#" - I thought you may have fixed this as part of
#45 #45 but instead that
change allows the user to define the element type. Any chance you could
include the ability to change the id? I think others would be happy to have
this ability as well.

Your code is setup well to allow for this change easily, something like so
is all I need:
Addition on the Extension:

public static IHtmlString React(
this HtmlHelper htmlHelper,
string componentName,
T props,
string htmlTag = null,
string htmlId = null
)
{
var reactComponent = Environment.CreateComponent(componentName, htmlId,
props);
if (!string.IsNullOrEmpty(htmlTag))
{
reactComponent.ContainerTag = htmlTag;
}
var result = reactComponent.RenderHtml();
return new HtmlString(result);
}
Addition on ReactEnvironment:

public virtual IReactComponent CreateComponent(string componentName, string
componentDomId
, T props)
{
EnsureUserScriptsLoaded();

  • if (string.IsNullOrEmpty(componentDomId)) { _maxContainerId++;
    componentDomId = string.Format(CONTAINER_ELEMENT_NAME, _maxContainerId); } *
    var component = new ReactComponent(this, _config, componentName,
    componentDomId)
    {
    Props = props
    };
    _components.Add(component);
    return component;
    }

Thanks!

Reply to this email directly or view it on GitHub
#50.

@jhemminger
Copy link
Author

Wow great, thanks!

@jhemminger
Copy link
Author

Thanks again - especially for the quick turn around!

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

2 participants