import React, { Component } from 'react'
export default class Example extends Component {
constructor (props) {
super(props)
this.state = {
value: this.props.bool ? this.props.value1 : this.props.value2
}
}
componentWillReceiveProps (nextProps) {
// тут доступны пропсы делайешь проверку со стейтом и все что тебе нужно
if (nextProps.bool) {
this.setState({...this.state, value: nextProps.value1})
} else {
this.setState({...this.state, value: nextProps.value2}, () => {
// тут можно сделать что то еще
})
}
}
render () {
return (
<div>...</div>
)
}
}
SELECT *
FROM `content`
WHERE 'topic' = all
ORDER BY STR_TO_DATE(`time`, '%d.%m.%Y') DESC, `id` DESC
LIMIT 4
// // development config
const merge = require('webpack-merge');
const webpack = require('webpack');
const commonConfig = require('./common');
module.exports = merge(commonConfig, {
entry: [
'react-hot-loader/patch', // activate HMR for React
'webpack-dev-server/client?http://localhost:8080',// bundle the client for webpack-dev-server and connect to the provided endpoint
'webpack/hot/only-dev-server', // bundle the client for hot reloading, only- means to only hot reload for successful updates
'./index.js' // the entry point of our app
],
devServer: {
hot: true, // enable HMR on the server
stats: {
assets: true,
children: false,
chunks: false,
hash: false,
modules: false,
publicPath: false,
timings: true,
version: false,
warnings: true,
optimizationBailout: true,
colors: {
green: '\u001b[32m',
}
}
},
devtool: 'cheap-module-eval-source-map',
plugins: [
new webpack.HotModuleReplacementPlugin(), // enable HMR globally
new webpack.NamedModulesPlugin(), // prints more readable module names in the browser console on HMR updates
],
});
const merge = require('webpack-merge');
const {resolve} = require('path');
const commonConfig = require('./common');
module.exports = merge(commonConfig, {
entry: './index.js',
devtool: 'source-map',
output: {
filename: 'bundle.min.js',
path: resolve(__dirname, '../../dist'),
publicPath: '/',
},
stats: {
assets: true,
children: false,
chunks: false,
hash: false,
modules: false,
publicPath: false,
timings: true,
version: false,
warnings: true,
optimizationBailout: true,
colors: {
green: '\u001b[32m',
}
},
plugins: [],
});
var string = 'Автошина ТЮМЕНЬ 175/70';
var find = 'шина 175';
var particles = find.toLowerCase().split(' ');
string = string.toLowerCase();
var status = true;
for (var i = particles.length - 1; i >= 0; i--) {
if (string.indexOf(particles[i]) < 0)
{
status = false;
}
}
console.log('Содержит: ', status);
var hammertime = new Hammer(document.body, {
enable: true,
recognizers: [
[Hammer.Swipe, { direction: Hammer.DIRECTION_HORIZONTAL }]
]
});
hammertime.on('swipeleft', function(ev) {
// hide menu
});
hammertime.on('swiperight', function(ev) {
// show menu
});
var $button = $('button');
$('body').on('submit', 'form', function(e) {
e.preventDefault();
$button.addClass('is-busy');
var formData = !!window.FormData ? new FormData($(this)[0]) : $(this).serialize();
$.ajax({
url: '/request/url',
type: 'POST',
data: formData,
dataType: 'JSON',
contentType: false,
processData: false,
success: function(response) {
$button.removeClass('is-busy');
},
error: function(response) {
$button.removeClass('is-busy');
}
});
});
parentСomponent {
dataUpdate (data) {
// тут ты получаешь данные
},
render (
<childrenComponent dataUpdate={this.dataUpdate.bind(this)} />
)
}
childrenComponent {
props {
dataUpdate: func
}
//при любых изменениях данных передаешь их в родительскую функцию и родитель получает данные
}