Your problem is not that the attribute value is blank; it's that your attribute is neither a native html spec element or prefaced with data. From the JSX Gotchas pages:
If you pass properties to native HTML elements that do not exist in the HTML specification, React will not render them. If you want to use a custom attribute, you should prefix it with data-.
You should do something like this:
render(){
return <myComponent data-foo={ this.state.foo || '' } />
}
Update (as @alexander pointed out):
You also need to specify a backup empty string if data-foo can return null. I've updated my example
componentDidMountonly runs once, and the general concept of manually setting attributes via DOM access is very anti-react :)