Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
How to create button react component?

I created simple React app and need to add Button Component. Unfortunately my code is not working. How I can fix it? Button realisation (React):

import React from 'react';

const Button = (props) => {
    return <button className="button">
        {props.children}
    </button>;
}

export { Button };

Test code:

import React from 'react';
import { shallow } from 'enzyme';

import Button from './Button';

describe('Button', () => {
    /**

     * children - button text

     */

    it('Button with text', () => {
        const component = shallow(<Button>Button</Button>);

        expect(component.html()).toEqual('<button class="button">Button</button>');
    });
});

files in dir

Error in test:

 Expected: "<button class=\"button\">Button</button>"
 Received: null
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

can you please try this,

it('Button with text', () => {
        const component = shallow(<Button>Button</Button>);

        expect(component.html()).toEqual('<button class=\"button\">Button</button>');
    });
about 4 years ago · Juan Pablo Isaza Report

0

This import line:

import Button from './Button';

is asking the build to get the default export from the module, but you're exporting that component inside an object.

So either:

export default Button;

Or:

import { Button } from './Button';

(I'd also suggest adding parentheses around your JSX in your return, and importing some CSS specific to that component.)

function Button(props) {
  return (
    <button className="button">
      {props.children}
    </button>;
  );
}

export default Button;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!