0

Having some issues. First of all, I can't load or render any images, for example, logo in my code. Getting "You may need an appropriate loader to handle this file type error." I have a doubt, that something wrong with my webpack.config file, but i can't figure it out. There are two of them:

One:

var webpack = require('webpack');
module.exports = {
  entry: './modules/index',
  output: {
    filename: 'dist/ReactHotAPI.js',
    libraryTarget: 'umd',
    library: 'ReactHotAPI'
  },
  plugins: [
    new webpack.optimize.OccurenceOrderPlugin()
  ]
};

second:

module.exports = {
    module: {
        loaders: [
            { test: /\.css$/, loader: "style!css" },
            { test: /\.(jpe?g|png|gif|woff|woff2|eot|ttf|svg)(\?[a-z0-9=.]+)?$/,
              loader: 'url-loader?limit=100000' }]},            { test: /\.jade$/, loader: "jade?self" }
        ]
    },
    node: {
        fs: "empty"
    }
} 

i have made some changes adding types of images, but i'm not sure if i'm right.

Another issue. There are several files: pages.js

import React from 'react';
import { browserHistory } from 'react-router';
import styles from './AutoComplete.css';

import AutoComplete from './AutoComplete';
import AutoComplete2 from './AutoComplete';

export default class LoginPage extends React.Component {
  signUp() {
    browserHistory.push('/home');
  }

  render() {
    return (
        <div className="App">
            <div className="Page-Component">
                <p className={styles.AutoComplete}><AutoComplete text="AutoComplete" /></p>
                <p className={styles.White}></p>
                <p className={styles.AutoComplete}><AutoComplete2 text="AutoComplete2" /></p>

            </div>
        </div>

    );
  }

} 

and autocomplete.js

import React from 'react';
import './style.css';
import './AutoComplete.css';
//import './film.png';

export default class AutoComplete2 extends React.Component {
    constructor(props) {
        super(props);
        this.items = [
            'First',
            'Second',
            'Third',
            'Fourth',
            'Fifth',

        ];
        this.state = {
            suggestions: [],
            text: '',
        };
    }

    onTextChanged = (e) => {
        const value = e.target.value;
        let suggestions = [];
        if (value.length > 0) {
            const regex = new RegExp(`^${value}`, 'i');
            suggestions = this.items.sort().filter(v => regex.test(v));
            }
        this.setState (() => ({suggestions, text: value }));
    }

    SuggestionSelected (value) {
        this.setState (() => ({
            text: value,
            suggestions: [],
        }))
    }

    renderSuggestions () {
        const { suggestions } = this.state;
        if (suggestions.length === 0) {
            return null;
            }
        return (
            <ul>
                {suggestions.map((item) => <li onClick={() => this.suggestionSelected(item) }>{item}</li>)}
            </ul>
    );
}

    render() {
        const { text } = this.state;
        return (
            <div className="AutoComplete">
                <input value={text} onChange={this.onTextChanged} type="text" placeholder="&#61896; Enter movie name" charSet="utf-8" />

                {this.renderSuggestions()}
            </div>
        )
    }

    render() {
        const { text } = this.state;
        return (
            <div className="AutoComplete2">
                <input value={text} onChange={this.onTextChanged} type="text" placeholder="&#61896; Enter movie name" charSet="utf-8" />

                {this.renderSuggestions()}
            </div>
        )
    }
} 

Now AC text area field works with given array 'First','Second','Third', 'Fourth','Fifth', But i would like that data would be taken from api, for example: GET: [linkstarts={search_text}&linkends.

What changes should i make?

JohnKet
  • 13
  • 1
  • 4
  • have you google your question before posting a it? literally first 3 results of 5 seconds google search: [link1](https://blog.hellojs.org/importing-images-in-react-c76f0dfcb552) , [lin2](https://stackoverflow.com/questions/39999367/how-do-i-reference-a-local-image-in-react) – plat123456789 Feb 14 '19 at 05:51
  • Yes, i have tried these suggestions in link 2. With image types of png and svg, i'm getting error Module parse failed. You may need an appropriate loader to handle this file type error. SyntaxError: unexpected character `?` (1:0) with image type of jpeg, I'm getting error Module not found: error: cannot resolve `file` or `directory.` The image sits in the same directory as js file I'm very weak at react, so it's hard for me to know all the points of react – JohnKet Feb 14 '19 at 09:46
  • so png & svg is ok, but not jpeg? – plat123456789 Feb 14 '19 at 09:54
  • i don't understand why the script doesn't sees my file. Probably my configuration is wrong, but I'm afraid of editing it, cause i have almost no idea how to do it correctly. You can find a lot of suggestions in Google. Besides, my webpack-config files is not in the root directory. I have one more doubt- maybe the problem is in Windows? If so, I'm gonna try it on Linux in weekend. – JohnKet Feb 14 '19 at 10:14

0 Answers0