score:194

Accepted answer

your syntax is valid. jsx is syntax sugar for react.createelement(type) so as long as type is a valid react type, it can be used in jsx "tags". if button is null, your import is not correct. maybe button is a default export from component-library. try:

import {default as styledbutton} from "component-library";

the other possibility is your library is using commonjs exports i.e. module.exports = foo. in this case you can import like this:

import * as componentlibrary from "component-library";

update

since this is a popular answer, here a few more tidbits:

export default button              -> import button from './button'
                                      const button = require('./button').default
         
export const button                -> import { button } from './button'
                                      const { button } = require('./button')
         
export { button }                  -> import { button } from './button'
                                      const { button } = require('./button')
         
module.exports.button              -> import { button } from './button'
                                      const { button } = require('./button')

module.exports.button = button     -> import { button } from './button'
                                      const { button } = require('./button')

module.exports = button            -> import * as button from './button'
                                      const button = require('./button')

score:0

note that when you capitalized styledlibrary and it worked

whereas, in the original question, you did not capitalize styledbutton and it did not work

both of these are the expected results with react

so you didn't discover a workaround, you simply discovered the (documented) react way of doing things

score:4

no idea why i am not able to alias the import;

as a work around, i ended up doing this:

import react, { proptypes } from "react";
import * as styledlibrary from 'component-library';

export default class button extends react.component {
    constructor(props){
        super(props)
    }
    render() {
        return (
            <styledlibrary.button {...this.props}></styledlibrary.button>
        )
    }
}

thanks all

score:5

user-defined components must be capitalized
https://reactjs.org/docs/jsx-in-depth.html#user-defined-components-must-be-capitalized

change your code to

import { button as styledbutton } from 'component-library';
....bah...bah....bah  
<styledbutton {...this.props}></styledbutton>

score:9

careful with capitalisation. best to always camelcase.

one:

import thing from "component";

one with alias:

import {thing as otherthing} from "component";

one with alias plus other defaults:

import {thing as otherthing}, stuff, fluff from "component";

more detailed example

import
{thing as styledbutton},
{stuff as stuffing},
{fluff as fluffy},
wool,
cotton
from "component";

score:21

try to import this way

import {default as styledlibrary} from 'component-library';

i suppose you export

export default styledlibrary

Related Query

More Query from same tag